Recursive access to editor

Recursive access to editor

aschippersaschippers Posts: 22Questions: 8Answers: 3

Hello,

I'm spending a couple of hours now on recursive starting up an editor.create window after submitting the previous row.

    production_delivery_registrations_multiple_editor.on('submitComplete', function(e, data, action) {
        // production_delivery_registrations_create_multiple();
        $('.btn-add-multiple').click();
    });

Both lines will trigger creation of a new record, but because the previous record is saved, but the javascript code isn't ended yet. This causes strange behaviour.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    I'm not sure what your code is doing on submitComplete. But I have done something similar and had to put a small delay, using setTimeout before calling the function that invokes a new create window. Without the delay there seems to be a race condition that causes the page to stop functioning after the first submit.

    Kevin

  • aschippersaschippers Posts: 22Questions: 8Answers: 3

    Thanks. My second intention was to do this by button click.I'll look at the timeOut.

    $('.btn-add-multiple).delay(1000).click() doesn't work.

    Creating a second button on which is clicked (to get submitComplete) ready and the second button clicks on the button, also gives the race condition.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Dopes delay work with click()? The documentation refers only to the jQuery event queue.

    Try:

    setTimeout( function () {
      $('.btn-add-multiple').click();
    }, 100 );
    

    Allan

  • aschippersaschippers Posts: 22Questions: 8Answers: 3

    Ok, i got it working

        production_delivery_registrations_multiple_editor.on('submitComplete', function(e, data, action) {
            // Logischerwijs zou je opnieuw de functie willen aanroepen, maar dat werkt dus niet.
            // production_delivery_registrations_create_multiple();
            
            // Workaround zou kunnen zijn om automatisch nogmaals op de button te klikken.
            // $('.btn-add-multiple').click();
            setTimeout(function(){
                console.log("Timeout ");
                $('.btn-add-multiple').click();
            },500);
        });
    

    A timeout, less then 200 ms isn't working. for safety, i used 500 ms.

    Thanks for time.

    Alan, you may close this item.

This discussion has been closed.