开发者

How to prevent jQuery Validate from validating when closing dialogs

I have javascript like

http://jsfiddle.net/8JXTk/1/

just a snipplet ...

$dialog.dialog({
  title: "Add Link",
  buttons:开发者_StackOverflow中文版 {
    "Add Link": function() {
      var $this = $(this);
      if ($this.valid()) {
        alert($this.find("input[name=txtURL]").val());
      } else {
        $this.find("input.error:first").effect("highlight").focus();
      }
    },
    "Cancel": function() {
      $(this).dialog("close");
    }
  },
  open: function() {
    $this = $(this);
    $this.find("input[name=txtURL]").val("http://").focus();
  }
});

as you can see the handler for cancel button is just to close the dialog. why is the validation running when I cancel the dialog? (When you cancel, you can see the flash of the error appearing)


Replace

$dialog.validate({

with

$('.markdownEditorDialogs').validate({

You are validating the dialog, but you must validate just the form you created.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜