16. Editor: Field is still processing

16. Editor: Field is still processing

rf1234rf1234 Posts: 2,358Questions: 76Answers: 339

I try to migrate from Editor 1.9.3 to 2.0.6. This has been my 5th attempt and I failed again.
Now I have this problem: https://datatables.net/manual/tech-notes/16

It says it is a problem to code "dependent" like this:

Obviously it is a problem in Editor 2.0.6. Had lots of stress this morning to figure it out - after making another rollback in the live system ...

It was no problem in Editor 1.9.3. Why is it now? Is there an easy way to resolve it without changing the code? I have 339 occurences of "dependent" in my code.

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 2,358Questions: 76Answers: 339

    @allan
    I saw your reply here: https://datatables.net/forums/discussion/70297/

    Not encouraging for me ... Is there no way out for me? Making 339 changes in my code feels like serving 6 months in jail.

  • allanallan Posts: 56,837Questions: 1Answers: 9,035 Site admin
    Answer ✓

    I'm afraid that this is correct - you need to tell Editor that the dependent() method has finished processing somehow. A return {}; will do that. The other option is to tweak the dependent code to just accept an undefined return.

    Sorry, it was an improvement - it should have been implemented like that originally.

    On the plus side, it won't take 6 months :).

    Allan

  • rf1234rf1234 Posts: 2,358Questions: 76Answers: 339

    I inserted

    callback({});
    

    everywhere.

    It was a bit tricky when making server calls with logical alternatives inside “dependent” not involving a server call. I wanted to avoid that the callback gets triggered before the server call is completed. Even though I am not sure whether that would make a difference in my cases.

    Here is an example:

    editor.dependent('contract.govdept_id', function (val, data, callback) {
        if (val > '0' && data.values['contract.iban'] <= '') {
            $.ajax({
                type: "POST",
                url: 'actions.php?action=getIban',
                async: true,
                data: {govdeptId: val},
                dataType: "json",
                success: function (data) {
                    editor.set({'contract.iban': data.iban});
                    callback({});
                }
            });
        } else {
            callback({});
        }
    })
    

    The usual synchronous cases were rather simple like this:

    editor.dependent('contract.expired', function ( val, data, callback ) {
        if (val == '1') {
            editor.show( ['contract_exp_date.exp_date'] );
        } else {
            editor.hide( ['contract_exp_date.exp_date'] );
        }
        callback({});
    })
    
  • allanallan Posts: 56,837Questions: 1Answers: 9,035 Site admin
    Answer ✓

    Yes, that looks spot on. Nice one.

    Allan

  • zajczajc Posts: 65Questions: 9Answers: 2
    edited August 3

    I have one question. What if we have several ajax calls inside one (1) dependent. Should we write callback({}); inside success in every ajax inside this one dependent?

  • rf1234rf1234 Posts: 2,358Questions: 76Answers: 339
    edited August 3

    If all of those ajax calls produce results that should be considered for the "dependent" actions you would need to make sure the callback comes at the very end.

    I solved it by simply nesting the ajax calls and making the callback on "success" of the last one.

Sign In or Register to comment.