Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 24, 2013 @ 15:57
    Jeavon Leopold
    0

    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

    Jul 30, 2013 @ 09:32

    Hey Jeavon,

    Back from holiday, do you still need help with this one or is it already solved?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 30, 2013 @ 10:06
    Jeavon Leopold
    0

    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

    Jul 30, 2013 @ 10:07

    Ok will take a look :)

  • Comment author was deleted

    Aug 01, 2013 @ 13:29

    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); },

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 01, 2013 @ 13:56
    Jeavon Leopold
    0

    Wow, that's amazing, I think Microsoft should take that change back into the source of jquery.validate.unobtrusive.js!

    Thanks Tim.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 02, 2013 @ 16:07
    Jeavon Leopold
    0

    Interestingly it looks like the original unobtrusive library has been superseded....? https://www.nuget.org/packages/Microsoft.jQuery.Unobtrusive.Validation/

  • Comment author was deleted

    Aug 05, 2013 @ 12:47

    Ok and does that one behave with jquery.validate.js ?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 14, 2013 @ 15:14
    Jeavon Leopold
    0

    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

    Aug 14, 2013 @ 15:17

    Yeah think I do for backoffice use (so when you preview the form in the Contour section)

  • Will Phillips 8 posts 145 karma points c-trib
    Sep 20, 2013 @ 13:29
    Will Phillips
    1

    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.....

Please Sign in or register to post replies

Write your reply to:

Draft