Domanda

I am using mvc3 with the KendoUI window control to open up a partial view in a modal window.

I have a form with the popup that I am trying to validate before sending the form back to the server.

I have a click event on my main view that looks like

  $("#submit-campaign").live("click",function () {
    var form = $("#Send");
    $.validator.unobtrusive.parse($(form));
     form.validate();
    if (form.valid()) {
        console.log("valid");
    } else {
        console.log("invalid");
    }

});

However its always been returned as true even if I haven't added values to some of the required.

I have referenced the 3 javascript files like

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

What do I need to do so I am getting the actual validation state clientside from the popup?

È stato utile?

Soluzione

The correct way to check validation would be.

$("#submit-campaign").live("click",function () {
    var form = $("#Send");
    $.validator.unobtrusive.parse($(form));
    var val = form.validate();
    if (val.valid()) {
        console.log("valid");
    } else {
        console.log("invalid");
    }

});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top