jQuery UI dialog template and jQuery Validate

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?

  1. @model App.Models.RegisterModel  
  2. @{
  3.   ViewBag.Title = "Home";
  4. }

  5. @section featured {
  6. <section class="featured">
  7.     <div class="content-wrapper">
  8.         <hgroup class="title">
  9.             <h1>Welcome</h1>
  10.             <br />
  11.             <h2>@ViewBag.Message</h2>
  12.         </hgroup>
  13.         <p>
  14.      TEXT
  15.         </p>
  16.     </div>
  17. </section>
  18. }


  19.      <div id="MainUser">

  20.         <section class="featured">
  21.         <div class="content-wrapper">

  22.             @using (Html.BeginForm())
  23.             {
  24.                 @Html.AntiForgeryToken()
  25.                 @Html.ValidationSummary()

  26.                 <fieldset>
  27.                     <legend>Registration Form</legend>
  28.                     <ol>
  29.                                          <li>
  30.                             @Html.LabelFor(m => m.UserName)
  31.                             @Html.TextBoxFor(m => m.UserName)
  32.                         </li>
  33.                      </ol>
  34.                     <input type="submit" value="Register" />
  35.                     @*<button data-bind="jqButton: {}, click: $root.accept">Accept</button>*@
  36.                     @*<button data-bind="jqButton: {}, click: $root.cancel">Cancel</button>*@
  37.                 </fieldset>               
  38.             }
  39.         </div>
  40.     </section>

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

  42. <script id="addUserTemplate" type="text/html">

  43.     <hgroup class="title">
  44.         <h1>@ViewBag.Title.</h1>
  45.         <h2>Create a new account.</h2>
  46.     </hgroup>

  47.     <section class="featured">
  48.         <div class="content-wrapper">

  49.                     @using (Html.BeginForm())
  50.                     {
  51.                         @Html.AntiForgeryToken()
  52.                         @Html.ValidationSummary()
  53.                         <fieldset>
  54.                       <legend>Registration Form</legend>
  55.                       <ol>
  56.                           <li>
  57.                               @Html.LabelFor(m => m.UserName)
  58.                               @Html.TextBoxFor(m => m.UserName)
  59.                           </li>
  60.                           @*                 <li>
  61.                             @Html.LabelFor(m => m.UserName)<span data-bind="text: $root.isUserNameValid"></span>
  62.                             @Html.TextBoxFor(m => m.UserName, new { data_bind = "value: $root.EditUserName, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
  63.                         </li>
  64.                         <li>
  65.                              @Html.LabelFor(m => m.Email)
  66.                             <span data-bind="text: $root.isEmailValid"></span>
  67.                             @Html.TextBoxFor(m => m.Email, new { data_bind = "value: $root.EditEmail, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
  68.                         </li>
  69.                         <li>
  70.                              @Html.LabelFor(m => m.Password)
  71.                             @Html.TextBoxFor(m => m.Password, new { data_bind = "value: $root.EditPassword, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
  72.                         </li>
  73.                         <li>
  74.                              @Html.LabelFor(m => m.ConfirmPassword)
  75.                             @Html.TextBoxFor(m => m.ConfirmPassword, new { data_bind = "value: $root.EditConfirmPassword, valueUpdate: 'keyup', event: { keyup: $root.DoesUserExist }" })
  76.                         </li>*@
  77.                       </ol>
  78.                       <input type="submit" value="Register" />
  79.                       @*<button data-bind="jqButton: {}, click: $root.accept">Accept</button>*@
  80.                       @*<button data-bind="jqButton: {}, click: $root.cancel">Cancel</button>*@
  81.                   </fieldset>               
  82.                     }      


  83.         </div>


  84.     </section>

  85. </script>


  86. </div>

  87.                               @section Scripts {


  88.                               @Scripts.Render("~/bundles/userVm")
  89.                               @Scripts.Render("~/bundles/jqueryval")
  90.                           }