This is a migrated thread and some comments may be shown as answers.

Clientside validation on window using mvc3

1 Answer 223 Views
Window
This is a migrated thread and some comments may be shown as answers.
Shane P
Top achievements
Rank 1
Shane P asked on 08 Feb 2012, 06:39 AM
I am attempting to use the kendoui window in an mvc3 project I am working on.

Scenario is I am wanting to use the window as nice way to insert data and validate the data clientside before sending back to the server.

The window contains it's own form and I am trying to post the data back to the server via ajax.

$("#submit-form").click(function () {
      console.log("called");
      var form = $("#Send");
      $.validator.unobtrusive.parse($(form));
      var val = form.validate();
      if (val.valid()) {

The form isn't anything special standard asp.net mvc stuff

<div>
                     @Html.LabelFor(model => model.CampaignName)
                     @Html.EditorFor(model => model.CampaignName)
                     @Html.ValidationMessageFor(model => model.CampaignName)
                 </div>


I have tried added reference to the validation scripts
<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>

However......everytime I try submit the form validation is always telling me its valid even tho I know its not.

Is there something special I need to do so I can enable clientside validation in the window?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 10 Feb 2012, 06:00 PM
Hello Shane,

There is nothing special you need to do when using validation in the Window. However, you should use the parse method once when the content is loaded. The Window's refresh event could be used for that purpose e.g.
$("#window").kendoWindow({
        content: "Home/FormData",
        refresh: contentRefreshed
    });
     
function contentRefreshed(e) {
    $.validator.unobtrusive.parse($("#window"));
    var form = $("#window").find('form');
    form.submit(function () {
        if (form.validate().valid()) {
            ....
        }
    });
}


Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Window
Asked by
Shane P
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or