My JavaScript code puts up a dialog box requesting some information from a user, as well as two buttons (OK and Cancel). I would like to use dialog‘s beforeClose handler to validate input when a user clicks the OK button (so that if the user didn’t make the proper input, he/she is still “in” the dialog box and has a chance to correct it). Is there a way of telling which of my two buttons was pressed? (obviously if the user pressed Cancel, then no input validation is necessary and the dialog box can just go ahead and close – i.e. my beforeClose can return true). I see that beforeClose takes two inputs, event and ui but neither of these appear to contain the information I want.
My JavaScript code puts up a dialog box requesting some information from a user,
Share
I have these all over one of my apps, and rather than dinking around with custom validation I just throw in an inline validation on the form in the dialog. It will do the intercept for you, easily validate the fields, and if it’s correct, let it fly. If not, it’ll automatically do the notification.
You certainly COULD home-brew this solution, but someone’s already done the work for you. Save your code for a bigger problem.
If you were determined to do it yourself, simply put the action in the button function as described in the documentation.