I'm trying to update a field with te value of an other one in Editor but no success

I'm trying to update a field with te value of an other one in Editor but no success

GuirauteGuiraute Posts: 8Questions: 3Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Answers

  • GuirauteGuiraute Posts: 8Questions: 3Answers: 0

    My script :
    editor.on('preSubmit', function (e, o, action) {
    let valeur = this.field('regions.code_acr').val() //Ok
    //alert('ça roule '+valeur)
    editor.val('inscriptacr.regionacr', valeur )
    editor.submit();
    });

    Why can't I update 'inscriptacr.regionacr' ?

  • rf1234rf1234 Posts: 3,079Questions: 89Answers: 427
    edited March 24

    I think you are using the wrong event handler.

    If you want to manipulate the editor form data using

    editor.val('inscriptacr.regionacr', valeur )
    

    for example, you should use "initSubmit" to do that.
    https://editor.datatables.net/reference/event/initSubmit

    Using "preSubmit" you need to manipulate the object to be sent to the server directly. In your code that is parameter "o".

    You would only use "preSubmit" for really complex stuff like this for example:

    editor
        .on( 'preSubmit', function( e, d, action ) {
            var opts = $.extend(true, [], ctrGovdeptOptions);
            var deptsReadOnlyArray = $.grep(opts, function(obj) {
                return obj.editor < 1; //only depts where the user only has reading rights!
            });
            if ( deptsReadOnlyArray.length > 0 ) {
                //get rid of unrequired attributes and rename "value" to "id"
                deptsReadOnlyArray.forEach( function(data) {
                    data['id'] = data['value'];
                    delete data['value'];
                    delete data['label'];
                    delete data['editor'];
                });
                var key = Object.keys(d.data)[0];
                d.data[key].ctr_govdept.push.apply(d.data[key].ctr_govdept, deptsReadOnlyArray);
                d.data[key].ctr_govdept = removeDuplicatesArrayOfObjects(d.data[key].ctr_govdept);
            }
        })
    
  • GuirauteGuiraute Posts: 8Questions: 3Answers: 0

    Thank you Very much rf1234,
    It works fine now

    Best regards,

    Francis

Sign In or Register to comment.