jQuery UI dialog template and jQuery Validate
Hi all,
I am working with MVC 4, jQuery UI and jQuery Validation. Also knockout but thats not an issue.
My problem is that I can get the validation to work on the view. But when I open the jQuery UI dialog as a template and have some input fields there, the validation doesn't seem to trigger.
Here is my code - what am I missing? Is it scoping? In that case how come Knockout is working?
- @model App.Models.RegisterModel
- @{
- ViewBag.Title = "Home";
- }
- @section featured {
- <section class="featured">
- <div class="content-wrapper">
- <hgroup class="title">
- <h1>Welcome</h1>
- <br />
- <h2>@ViewBag.Message</h2>
- </hgroup>
- <p>
- TEXT
- </p>
- </div>
- </section>
- }
- <div id="MainUser">
- <section class="featured">
- <div class="content-wrapper">
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- @Html.ValidationSummary()
- <fieldset>
- <legend>Registration Form</legend>
- <ol>
- <li>
- @Html.LabelFor(m => m.UserName)
- @Html.TextBoxFor(m => m.UserName)
- </li>
- </ol>
- <input type="submit" value="Register" />
- @*<button data-bind="jqButton: {}, click: $root.accept">Accept</button>*@
- @*<button data-bind="jqButton: {}, click: $root.cancel">Cancel</button>*@
- </fieldset>
- }
- </div>
- </section>
- <div style="background-color: White;" id="addUser" data-bind="jqDialog: { autoOpen: false, resizable: false, modal: true, width: 500 }, template: { name: 'addUserTemplate', data: $root.newUser, if: $root.newUser }, openDialog: $root.newUser"></div>
- <script id="addUserTemplate" type="text/html">
- <hgroup class="title">
- <h1>@ViewBag.Title.</h1>
- <h2>Create a new account.</h2>
- </hgroup>
- <section class="featured">
- <div class="content-wrapper">
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- @Html.ValidationSummary()
- <fieldset>
- <legend>Registration Form</legend>
- <ol>
- <li>
- @Html.LabelFor(m => m.UserName)
- @Html.TextBoxFor(m => m.UserName)
- </li>
- @* <li>
- @Html.LabelFor(m => m.UserName)<span data-bind="text: $root.isUserNameValid"></span>
- @Html.TextBoxFor(m => m.UserName, new { data_bind = "value: $root.EditUserName, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
- </li>
- <li>
- @Html.LabelFor(m => m.Email)
- <span data-bind="text: $root.isEmailValid"></span>
- @Html.TextBoxFor(m => m.Email, new { data_bind = "value: $root.EditEmail, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
- </li>
- <li>
- @Html.LabelFor(m => m.Password)
- @Html.TextBoxFor(m => m.Password, new { data_bind = "value: $root.EditPassword, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
- </li>
- <li>
- @Html.LabelFor(m => m.ConfirmPassword)
- @Html.TextBoxFor(m => m.ConfirmPassword, new { data_bind = "value: $root.EditConfirmPassword, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
- </li>*@
- </ol>
- <input type="submit" value="Register" />
- @*<button data-bind="jqButton: {}, click: $root.accept">Accept</button>*@
- @*<button data-bind="jqButton: {}, click: $root.cancel">Cancel</button>*@
- </fieldset>
- }
- </div>
- </section>
- </script>
- </div>
- @section Scripts {
- @Scripts.Render("~/bundles/userVm")
- @Scripts.Render("~/bundles/jqueryval")
- }