-
Guys, Background : I have succesfully used Now : I have a single form ( php + html ) ( as above ) but however with 4 submit buttons. : The php/html form code is a below ( with 4 submit buttons ) :
: The JS Code ( how do I modify bootbox.confirm to work with 4 submit buttons ) is as below :
Question : How do I get 4 submit buttons( only 1 button will be used at a time ) to work with bootbox.confirm ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
I've moved your question into a Discussion - please only use the Issues tab to report problems with the library. |
Beta Was this translation helpful? Give feedback.
-
document.addEventListener('DOMContentLoaded', function () {
let formHandled = false;
const form1 = document.getElementById('pageForm1');
if( form1 ){
form1.addEventListener('submit', event => {
let btn = document.getElementById(event.submitter.id);
if( !formHandled ) {
event.preventDefault();
bootbox.confirm({
size: 'small', centerVertical: true,
message: 'Proceed With Action?',
callback : function(result) {
if( result ) {
formHandled = true;
if ( btn ){
btn.click();
}
} else {
formHandled = false;
}
}
}); // end bootbox.confirm
return false;
}// end of if( !formHandled )
}); //end of form1.addEventListener
} // end of if form1
}); You don't need to track the individual buttons - See https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent/submitter and this jsFiddle: https://jsfiddle.net/70gsytnz/3/ |
Beta Was this translation helpful? Give feedback.
From the docs, that's what I was assuming, but... thinking about it, the event you're handling is the form's submit event. So, while a button is the logical trigger for the submit event, from the event object's perspective, it's the form itself which raised the event. So... my suggestion probably doesn't work as-is.
To be honest, this isn't really a Bootbox "problem", but I'll spend a little bit of time and see if I can come up with a better suggestion.