Reputation: 29694
I'm writing a new custom validator for MVC4. Done this several times. This time though I need to know which submit button was pressed, there are multiple submits on the form which do slightly different things based on their value.
Given the common way of writing a new adapter:
$.validator.unobtrusive.adapters.add(
'requiredforsubmitvalue', ['submitValue'], function (options) {
options.rules['requiredforsubmitvalue'] = options.params;
options.messages['requiredforsubmitvalue'] = options.message;
});
$.validator.addMethod("requiredforsubmitvalue", function (value, element, params) {
//which submit button pressed?
});
How do I identify which submit button has been pressed? Is this even possible?
Upvotes: 2
Views: 75
Reputation: 93571
This should give you the focused (pressed) submit button:
var btn = $("input[type=submit]:focus");
Upvotes: 2