I'm looking for ideas on how to override/replace the functionality of the onErrors method in jquery.validate.unobtrusive.js for my Validation Groups project (MVC3 Validation Groups - http://bit.ly/zRmxwD). Does any one have any idea?
My initial attempts failed before the method (and assignment) is scoped to a JQuery document Load event handler.
Hi, thanks for the response. The method you use in that post appears to be the same that I'm currently using, ie. modifying the original js file. What I'm hoping for is a way to amend the functionality without editing that file.
Still, it's a very interesting feature that you've created!
Hi, this doesn't seem to affect anything it runs successfully by the original onErrors function still get's called. It looks like the function that gets called is the version assigned when the document is first parsed (which happens right at the end of
the standard script, before the next script runs).
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
The code runs (after the unobtrusive validation script) and I see the 'Correctly Assigned!' alert box for each form, but the old function still runs when there are validation errors.
I've also tried assigning the values back into data with the same results:
$('form').each(function (i, form) {
$form = $(form);
var val = $form.data('validator');
val.settings.invalidHandler = onGroupedErrors;
$form.data('validator', val)
if (val.settings.invalidHandler === onGroupedErrors) alert("Correctly Assigned!");
});
The 'onGroupedErrors' function works when I edit the standard 'jquery.validate.unobtrusive.js' file and replace 'onErrors'.
Yes I believe this will work because jQuery validate plugin added the invalidHandler directly into this event.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
martincjarvi...
Member
68 Points
25 Posts
How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 10:39 AM|LINK
Hi,
I'm looking for ideas on how to override/replace the functionality of the onErrors method in jquery.validate.unobtrusive.js for my Validation Groups project (MVC3 Validation Groups - http://bit.ly/zRmxwD). Does any one have any idea?
My initial attempts failed before the method (and assignment) is scoped to a JQuery document Load event handler.
Thanks,
Martin
kedarrkulkar...
All-Star
34013 Points
5468 Posts
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 11:59 AM|LINK
recently I posted article on getting validation callout like popup in place of normal validation message displayed in MVC + unobtrusive script.
u can rea the full articve here
http://www.bluelemoncode.com/post/2011/12/17/Implementing-validation-callout-in-Aspnet-MVC-(with-data-annotations).aspx
you might get some clue to work with your requirement from here.
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
martincjarvi...
Member
68 Points
25 Posts
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 12:35 PM|LINK
Hi, thanks for the response. The method you use in that post appears to be the same that I'm currently using, ie. modifying the original js file. What I'm hoping for is a way to amend the functionality without editing that file.
Still, it's a very interesting feature that you've created!
Regards,
Martin
bruce (sqlwo...
All-Star
36644 Points
5432 Posts
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 03:24 PM|LINK
just override it in jquery validater
$(function() {
$('form').validate().settings.invalidHandler = function(f,v) {
});
});
just be sure your code is after the unobtrusive include.
martincjarvi...
Member
68 Points
25 Posts
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 03:50 PM|LINK
Hi, this doesn't seem to affect anything it runs successfully by the original onErrors function still get's called. It looks like the function that gets called is the version assigned when the document is first parsed (which happens right at the end of the standard script, before the next script runs).
Thanks for the suggestion!
imran_ku07
All-Star
45785 Points
7698 Posts
MVP
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 04:00 PM|LINK
See this.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
martincjarvi...
Member
68 Points
25 Posts
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 04:17 PM|LINK
I think I must be being thick...I adapted that approach and got this:
$('form').each(function (i, form) {
$form = $(form);
var settings = $form.data('validator').settings;
settings.invalidHandler = onGroupedErrors;
if (settings.invalidHandler === onGroupedErrors) alert("Correctly Assigned!");
});
The code runs (after the unobtrusive validation script) and I see the 'Correctly Assigned!' alert box for each form, but the old function still runs when there are validation errors.
I've also tried assigning the values back into data with the same results:
$('form').each(function (i, form) {
$form = $(form);
var val = $form.data('validator');
val.settings.invalidHandler = onGroupedErrors;
$form.data('validator', val)
if (val.settings.invalidHandler === onGroupedErrors) alert("Correctly Assigned!");
});
The 'onGroupedErrors' function works when I edit the standard 'jquery.validate.unobtrusive.js' file and replace 'onErrors'.
Can anyone advise on what I'm doing wrong?
bruce (sqlwo...
All-Star
36644 Points
5432 Posts
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 04:36 PM|LINK
sorry the bind is done in the init. just
$('form').each(function() { $(this).unbind("invalid-form.validate"); // remove old handler $(this).bind("invalid-form.validate",function(f,v) { }); });imran_ku07
All-Star
45785 Points
7698 Posts
MVP
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 05:12 PM|LINK
Yes I believe this will work because jQuery validate plugin added the invalidHandler directly into this event.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
martincjarvi...
Member
68 Points
25 Posts
Re: How to overide the 'onErrors' method of jquery.validate.unobtrusive.js
Jan 17, 2012 07:18 PM|LINK
That did it! Thanks you very much!