2
votes

I have several submit buttons in form. How to determine in "beforeSubmit" callback which button initiated submitting the form?

    $('#myForm').ajaxSubmit({
        beforeSubmit(arr, $form, options)
        {
          // here we need to determine which button has initiated
          // submitting the form?
        }
    }

Unfortunately, arr does not contain any submit buttons fields.

concole.log(arr);

    
    [Object, Object, Object]
      0: Object
       name: "enabled"
       required: false
       type: "checkbox"
       value: "1"
       __proto__: Object
      1: Object
       name: "position"
       required: false
       type: "hidden"
       value: "headertop"
       __proto__: Object
      2: Object
       name: "index"
       required: false
       type: "hidden"
       value: "0"
       __proto__: Object
     length: 3
     __proto__: Array[0]

I have only one form and that form has two submit buttons.
Form looks like this:
<form id="myForm" method="post" action="/admin/settings/template_save"> <input name="enabled" type="checkbox" value="1" checked="checked"> <input name="delete" type="submit" value="Delete"> <input name="save" type="submit" value="Save"> <input type="hidden" name="position" value="headertop"> <input type="hidden" name="index" value="0"> </form>
Their documentation also does not describe this issue.
Please help.
Thanks!

1
you have more then one submit buttons for same form? or different forms & different submit buttons for these forms? - epipav
I have only one form and that form has two submit buttons. - abdulmanov.ilmir

1 Answers

1
votes

As with any event callbackFunction the event is passed to your function as the first object. So you just check if the button is the one you expect, example:

function onSubmitHandler(e){
    var btnClicked = e.target;
    if (btnClicked.id === "expectedBtnId") {
        // work
    }
}