Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 2.66 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jQuery UI Dialog Will Not Close
  2. $(function () {
  3.     $(".editLink").button();
  4.  
  5.     $('#editPersonDialog').dialog({
  6.         autoOpen: false,
  7.         width: 800,
  8.         resizable: false,
  9.         title: 'Edit Person',
  10.         modal: true,
  11.         buttons: {
  12.             "Save": function () {
  13.                 $("#update-message").html('');
  14.                 $("#updatePersonForm").submit();
  15.             },
  16.             "Close": function () {
  17.                 $(this).dialog('close');
  18.             }
  19.         },
  20.         close: function (event, ui) {
  21.             $(this).dialog('close');
  22.         }
  23.     });
  24.  
  25.     $(".editLink").click(function () {
  26.         var dialogDiv = $('#editPersonDialog');
  27.         var linkObj = $(this);
  28.         var viewUrl = linkObj.attr('href');
  29.         $.get(viewUrl, function (data) {
  30.             dialogDiv.html(data);
  31.             //validation
  32.             var $form = $("#updatePersonForm");
  33.             // unbind existing validation
  34.             $form.unbind();
  35.             $form.data("validator", null);
  36.             // check document for changes
  37.             $.validator.unobtrusive.parse(document);
  38.             // re-add validation with changes
  39.             $form.validate($form.data("unobtrusiveValidation").options);
  40.             // open dialog
  41.             dialogDiv.dialog('open');
  42.         });
  43.  
  44.         return false;
  45.     });
  46. });
  47.  
  48. function updateSuccess() {
  49.     if ($("#update-message").html() == "True") {
  50.         $('#editPersonDialog').dialog('close');
  51.         $("#commonMessage").html("Update Complete");
  52.         $("#commonMessage").delay(400).slideDown(400).delay(3000).slideUp(400);
  53.     }
  54.     else {
  55.         $("#update-message").show();
  56.     }
  57. }
  58.        
  59. @using (Ajax.BeginForm("Edit", "Person", null,
  60.     new AjaxOptions
  61.     {
  62.         UpdateTargetId = "update-message",
  63.         InsertionMode = InsertionMode.Replace,
  64.         HttpMethod = "POST",
  65.         OnSuccess = "updateSuccess"
  66.     },
  67.     new { @id = "updatePersonForm" }))
  68. {
  69.     @Html.ValidationSummary(true)
  70.     <div id="update-message"  class="hiddenDiv"></div>
  71.     <div class="blockGraygradient">
  72.         @Html.Partial("_CreateEditCommon")
  73.         @Html.HiddenFor(model => model.SelectedPerson.Id)
  74.         @Html.HiddenFor(model => model.SelectedPerson.RowVersion)
  75.         @Html.HiddenFor(model => model.SelectedPerson.CreateTime)
  76.     </div><p/>
  77. }
  78.        
  79. $(this).dialog('destroy');
  80.        
  81. $('#editPersonDialog').dialog({
  82.     autoOpen: false,
  83.     width: 800,
  84.     resizable: false,
  85.     title: 'Edit Person',
  86.     modal: true,
  87.     buttons: {
  88.         "Save": function () {
  89.             $("#update-message").html('');
  90.             $("#updatePersonForm").submit();
  91.         },
  92.         "Close": function () {
  93.             $(this).dialog('close');
  94.         }
  95.     }
  96. });