jQuery UI Dialog + Validate

怎甘沉沦 提交于 2019-12-03 12:51:33
Attila Szasz

When you initialize the jQueryUI dialog, it modifies the DOM, the whole dialog is taken out of it's location in the page and inserted right before the </body> tag. You can see this with Firebug. This causes a problem for Validate, because now the form is empty. To solve this, on the dialog's open event, append it to the form. It sounds really wacky, but trust me, it works :)

dialog.dialog({
    title: a.attr('title') ? a.attr('title') : '',
    modal: true,
    buttons: {
      'Save': function() {submitFormWithAjax($(this).find('form'));},
      'Cancel': function() {$(this).dialog('close');}
    },
    close: function() {$(this).remove();},
    open: function(){
        $(this).parent().appendTo($('#event_form'));
    },
    width: 'auto'
  });

Edit:

<form id='event_form'>
  <div id="dialog" title="DialogTitle"> 
  </div>
</form>

Took a slightly different approach to this. I needed to reuse my modal form so I append it once jquery "creates" the modal:

    $("#mdl_Subject").dialog({
    autoOpen: false,
    show: "drop",
    hide: "drop",
    modal: true,
    create: function () {
        $(this).parent().appendTo($('#aspnetForm'));
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!