0

i have tried multiple ways to allow this function to work - referred to a variety of jquery... and none work. can someone tell me what i'm doing wrong. i read its the order of how things are referred to... i tried changing that. i read its the bundle config... i edited that. i read its the jquery version.. i changed that... i read abt migrate... did that... nothing seems to work. i dont understand what i'm doing wrong.

EDIT removed some lines from head tag. left with the following. but the .valid is still not working..:

<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - COMIS</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

<link href="~/Content/themes/base/jquery.ui.core.css" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="stylesheet" 
type="text/css" />

<script src="~/Scripts/jquery-1.11.1.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-migrate-1.2.1.js" type="text/javascript"></script>
<script src="~/Scripts/datepicker.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>

<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css") 
@Styles.Render("~/Content/themes/base/css") 
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery") 
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/jqueryval") 
@Scripts.Render("~/Scripts/buttons.js") 
@Scripts.Render("~/Scripts/navigation.js")

function

 $(function () {
global.initButtons();
  });

     var global = {
  initButtons: function () {
    $('a.button.positive').click(function (e) {
        e.preventDefault();
        var parentForm = $(this).closest('form');

        if (!parentForm.valid()) {
            $("form").validate();
            //                    global.flashMessage('Error validating these values', 'error');
        }
        else {
            $(this).css(global.disableCss).unbind('click');
            parentForm.submit();
        }
    });
},
disableCss: { opacity: 0.5, display: 'inline-block' }
};
Sparky
  • 98,165
  • 25
  • 199
  • 285
New2This
  • 253
  • 1
  • 6
  • 22
  • 1
    You clearly have a misunderstanding about how JavaScript files are included. You've included everything multiple times. jQuery x 4, migrate x 3, UI x 3, datepicker x 3, Validate x 2. The only one you've included correctly is unobtrusive validation. – Sparky Oct 16 '14 at 21:54
  • @Sparky i'm now learning - its my very first project...i'm not sure which I should remove. I tried removing the ones you mentioned, but the .valid still isnt working... – New2This Oct 16 '14 at 22:09
  • 1
    `.validate()` is the INITIALIZATION method... you cannot call `.validate()` as a condition of `.valid()` since `.valid()` is meaningless without `.validate()`. Have you read the documentation? – Sparky Oct 16 '14 at 22:28
  • 1
    In other words, `.validate()` is called once on DOM ready (not within a click handler) to initialize the plugin. Then `.valid()` can be used to programmatically trigger a validation test. This page contains a lot of useful info: http://stackoverflow.com/tags/jquery-validate/info – Sparky Oct 16 '14 at 23:02
  • 1
    Your title: _"jquery valid throwing error although migrate included"_ ~ I guess it's also important for you to know that `.valid()` is not part of jQuery, it's part of the jQuery Validate plugin and would have nothing to do with jQuery Migrate. – Sparky Oct 16 '14 at 23:04

0 Answers0