js/pjax.js
// Collect form data and return it
Collect form data and return it
Collect form data and return it
function collectFormData(form) {
    var data = new FormData(form);
    var temp_fields = [];
    form.querySelectorAll('div.multi-language-input input[id], textarea[id]').forEach(elem => {
        var data = window[elem.getAttribute('id').split('_').slice(0, -1).join('_') + '_data'];
        var name = elem.getAttribute('data-name').split('_').shift();
        var prop = elem.getAttribute('data-name').split('_').pop();
        for(var language in data) {
            var localized_name = name + '[' + language + '][' + prop + ']';
            temp_fields.push(localized_name);
            var input = document.createElement('input');
            input.setAttribute('type', 'hidden');
            input.setAttribute('name', localized_name);
            input.value = data[language][prop].toString();
            form.appendChild(input);
        }
    });
    temp_fields.forEach(temp_field => {
        var field = form.querySelector('input[type="hidden"][name="' + temp_field + '"]');
        field.parentNode.removeChild(field);
    });
    var files = {}
    form.querySelectorAll('input[type="file"]').forEach(input => {
        var prop = input.getAttribute('name');
        if(!input.multiple === true) {
            files[prop] = elem.files[0];
        } else {
            prop += '[]';
            for(var i = 0; i < elem.files.length; i++) {
                files[prop] = elem.files[i];
            }
        }
    });
    for(var key in files) {
        data.append(key, files[key]);
    }
    return data;
}
function collectFormData ( form ) { var data = new FormData ( form ) ; var temp_fields = [ ] ; form . querySelectorAll ( 'div.multi-language-input input[id], textarea[id]' ) . forEach ( elem => { var data = window [ elem . getAttribute ( 'id' ) . split ( '_' ) . slice ( 0 , - 1 ) . join ( '_' ) + '_data' ] ; var name = elem . getAttribute ( 'data-name' ) . split ( '_' ) . shift ( ) ; var prop = elem . getAttribute ( 'data-name' ) . split ( '_' ) . pop ( ) ; for ( var language in data ) { var localized_name = name + '[' + language + '][' + prop + ']' ; temp_fields . push ( localized_name ) ; var input = document . createElement ( 'input' ) ; input . setAttribute ( 'type' , 'hidden' ) ; input . setAttribute ( 'name' , localized_name ) ; input . value = data [ language ] [ prop ] . toString ( ) ; form . appendChild ( input ) ; } } ) ; temp_fields . forEach ( temp_field => { var field = form . querySelector ( 'input[type="hidden"][name="' + temp_field + '"]' ) ; field . parentNode . removeChild ( field ) ; } ) ; var files = { } form . querySelectorAll ( 'input[type="file"]' ) . forEach ( input => { var prop = input . getAttribute ( 'name' ) ; if ( ! input . multiple === true ) { files [ prop ] = elem . files [ 0 ] ; } else { prop += '[]' ; for ( var i = 0 ; i < elem . files . length ; i ++ ) { files [ prop ] = elem . files [ i ] ; } } } ) ; for ( var key in files ) { data . append ( key , files [ key ] ) ; } return data ; }
Collect form data and return it
Collect form data and return it
// Multi language fields // remove temporary fields // file uploads