$(document).ready(function () {
    initialize();
    bindEvent();
});

function initialize() {
    bindMaktx();
}

function bindEvent() {
    $('#materialNameElement input').each(function() {
        let inputName = $(this).attr('name');
        if (inputName === 'id' || inputName === 'billCode' || inputName === 'maktx' || inputName ==='length') {
            return;
        }
        $('#materialNameElement #' + inputName).on('input', function() {
            bindMaktx();
        });
    });
}

function bindMaktx(){
    let formValues = [];
    $('#materialNameElement input').each(function() {
        let inputName = $(this).attr('name');
        if (inputName === 'id' || inputName === 'billCode' || inputName === 'maktx' || inputName ==='length') {
            return;
        }
        let inputValue = $(this).val();

        if (inputValue) {
            formValues.push(inputValue);
        }
    });
    let result = formValues.join('');
    //限定40个字符
    result = result.substring(0,40);
    $("#materialNameElement #maktx").val(result);
    $("#materialNameElement #length").val(result.length);
}