When using Contour Mvc rendered forms, the requirement to include jquery.validate.unobtrusive.min.js is an issue as it breaks other form validation using jquery.validate.js that is applied to non Contour forms on the page. Is there a way to not use the unobtrusive js with Contour?
Yes, this is still an issue for us, we have used jquery.validate normally a lot and so we have a problem as we cannot use the Contour Razor mode as adding the unobtrusive JS stops the standard jquery.validate from working. We have experimented with EnableClientValidation and EnableUnobtrusiveJavaScript but we have been unable to find a combination that works for everything or doesn't cause JS errors.
Basicly it's an addon at line 100 since the jquery.validate.unobtrusive.js code calls form.validate() even if no rules were found or created - destroying whatever you had done, so by adding a simple check...
This might be of use in the future if you are only wanting to use unobtrusive validation as we just came across this when we added a contour form onto a page that already had a form in it that was using some custom validator rules, its a bit of a dirty hack but it did the trick, in the jquery unobtrusive validation script, near the bottom there is a
$jQval.unobtrusive.parse(document);
we changed the document to only parse the contour form like so..
$jQval.unobtrusive.parse("#contour form");
Then within the parse function change
$("form").each(function () {
var info = validationInfo(this);
if (info) {
info.attachValidation();
}
});
to..
$("#contour form").each(function () {
var info = validationInfo(this);
if (info) {
info.attachValidation();
}
});
I hope this helps some other people out, if you like dirty hacks an all.....
jquery.validate.unobtrusive conflict
Hi,
When using Contour Mvc rendered forms, the requirement to include jquery.validate.unobtrusive.min.js is an issue as it breaks other form validation using jquery.validate.js that is applied to non Contour forms on the page. Is there a way to not use the unobtrusive js with Contour?
Thanks,
Jeavon
Comment author was deleted
Hey Jeavon,
Back from holiday, do you still need help with this one or is it already solved?
Hey Tim,
Welcome back, I hope you had a great break!
Yes, this is still an issue for us, we have used jquery.validate normally a lot and so we have a problem as we cannot use the Contour Razor mode as adding the unobtrusive JS stops the standard jquery.validate from working. We have experimented with EnableClientValidation and EnableUnobtrusiveJavaScript but we have been unable to find a combination that works for everything or doesn't cause JS errors.
Thanks,
Jeavon
Comment author was deleted
Ok will take a look :)
Comment author was deleted
Ok found a fix you'll need a custom version of the jquery validate unobtrusive script
Here is the updated version: https://www.dropbox.com/s/d3zww28c0zk66e6/jquery.validate.unobtrusive.js
Basicly it's an addon at line 100 since the jquery.validate.unobtrusive.js code calls form.validate() even if no rules were found or created - destroying whatever you had done, so by adding a simple check...
(!$.isEmptyObject(this.options.rules)) $form.validate(this.options); },
Wow, that's amazing, I think Microsoft should take that change back into the source of jquery.validate.unobtrusive.js!
Thanks Tim.
Interestingly it looks like the original unobtrusive library has been superseded....? https://www.nuget.org/packages/Microsoft.jQuery.Unobtrusive.Validation/
Comment author was deleted
Ok and does that one behave with jquery.validate.js ?
No, it has the same issue but in v2.0.30506.0 it's moved to line 118.
Strange that none of these updated versions are available on the MS CDN, seems it only carries the original Mvc3 version.
Do you ship the Unobtrusive js file with Contour?
Comment author was deleted
Yeah think I do for backoffice use (so when you preview the form in the Contour section)
This might be of use in the future if you are only wanting to use unobtrusive validation as we just came across this when we added a contour form onto a page that already had a form in it that was using some custom validator rules, its a bit of a dirty hack but it did the trick, in the jquery unobtrusive validation script, near the bottom there is a
$jQval.unobtrusive.parse(document);
we changed the document to only parse the contour form like so..
$jQval.unobtrusive.parse("#contour form");
Then within the parse function change
to..
I hope this helps some other people out, if you like dirty hacks an all.....
is working on a reply...