Is it possible to re-submit a form, while having "closeOnComplete" set to false?

Is it possible to re-submit a form, while having "closeOnComplete" set to false?

aop@mhcg.dkaop@mhcg.dk Posts: 15Questions: 4Answers: 0
edited June 2015 in Editor

Hi,

I am wondering if it is possible to re-submit a form (on enter press) while having "closeOnComplete" set to false?

Scenario: Edit row -> change a field -> press enter -> form is submitted -> change another field -> press enter -> submit again.

    editor = new $.fn.dataTable.Editor({
        ajax: "/add_n_edit",
        table: "#table",
        fields: fields,
        formOptions: {
            main: {
                onEsc: 'none',
                submitOnReturn: true,
                closeOnComplete: false
            }
        });

Tanks in advance.

This question has an accepted answers - jump to answer

Answers

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

    Hi,

    What you would need to do is trigger an edit on the same row again. The reason being is that the form has finished its edit so it has effectively been cleared and ready for the next edit.

    You could use the submitComplete event to trigger the next edit.

    Regards,
    Allan

  • aop@mhcg.dkaop@mhcg.dk Posts: 15Questions: 4Answers: 0
    edited June 2015

    ...

  • aop@mhcg.dkaop@mhcg.dk Posts: 15Questions: 4Answers: 0
    edited June 2015

    ...

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

    As in you can't give it focus at all? That sounds very odd indeed! Are you able to give me a link to the page so I can try it out?

    Thanks,
    Allan

  • aop@mhcg.dkaop@mhcg.dk Posts: 15Questions: 4Answers: 0

    Hi allan,

    No, i CAN give it focus, but only after the focus has been removed when submitting.. So i have to click twice on another input field to gain focus.

    Sadly i'm not able to give you a link. I'm not even able to make a fiddle. Sorry.

    Hopefully you can help me anyways. :-)

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

    Hi,

    It looks like you've removed your previous posts and I can't remember all of the details in them.

    Can you show me the code that you are using please?

    Allan

  • aop@mhcg.dkaop@mhcg.dk Posts: 15Questions: 4Answers: 0

    Hi Allan,

    My question is: When i do as you suggested, use the submitComplete event to trigger the next edit, FOCUS is lost from what ever i was doing. I.e. If i was editing in a textfield and it submits and reopens for a new submit, focus is lost and i have to click on that textfield again to resume typing. It seems like initializing a new edit removes focus from everything... Is there a way to avoid losing focus?

    NB: I am submitting the form every time a user stops typing for more than 1-2 seconds, therefore i need to reenable submitting.

    Thanks in advance.

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

    I've just tried to reproduce the issue using this example. I used the following code which you can run from your browser's console:

    setTimeout( function () {
      editor.edit( $('tbody tr:eq(0)'), { closeOnComplete: false, buttons: 'Save' } );
      editor.on( 'submitComplete', function ( ) {
        editor.edit( $('tbody tr:eq(0)'), { closeOnComplete: false, buttons: 'Save' } );
      } );
    }, 3000 );
    

    The setTimeout is just so you can click in the document to give it focus, rather than having the focus in the console!

    When I submit the row, it immediately then triggers an edit on the same row again and focus is retained.

    Are you able to modify that, or give me a link to your page showing the issue, so I can debug the problem please.

    Allan

  • aop@mhcg.dkaop@mhcg.dk Posts: 15Questions: 4Answers: 0
    edited July 2015

    ..

  • aop@mhcg.dkaop@mhcg.dk Posts: 15Questions: 4Answers: 0
    edited July 2015

    Fixed it. I set a timeout after submitcomplete focusing the field.

    Thanks

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

    Here is a modification to my code that uses the preSubmit event to store the element that has focus when the submit action is activated. That is then used to give it focus again in submitComplete:

      var element;
    
      editor.edit( $('tbody tr:eq(0)'), { closeOnComplete: false, buttons: 'Save' } );
    
      editor.on( 'preSubmit', function () {
        focus = document.activeElement;
      } );
    
      editor.on( 'submitComplete', function ( ) {
        editor.edit( $('tbody tr:eq(0)'), { closeOnComplete: false, buttons: 'Save' } );
        focus.focus();
      } );
    

    Allan

This discussion has been closed.