I am popping up a JQuery dialog which has a form inside.
<div class="addcalevent">
<form name="caleventform" id="caleventform" method="get" action="" accept-charset="utf-8">
<div>
<label>Title</label>
<input type="text" id="txtcaltitle" name="title" />
</div>
<button id="savecalevent" >save</button>
</form>
</div>
When i popup the dialog, i am initializing the Jquery validation plugin.
$(".addcalevent").dialog(
{
height: 300,
width: 546
}
);
$('#caleventform').validate({
rules: {
title: {
required: true,
}
},
messages: {
title: {
required: "pls enter user name"
}
}
});
Ob button click .valid() always returns true.
$('.addcalevent').on('click', "#savecalevent", function (event) {
if (!$('#caleventform').valid()) {
return;
}
});
What am i doing wrong ? I am using Jquery version 1.10.2 and Validate version 1.11.0, Does the validation works only with a "Submit" button ?
Thanks !
required="required"into your code should have absolutely no effect since you already have therequiredrule properly declared within the.validate()method. I have no idea how you're examining.valid()but it's working fine for me here: jsfiddle.net/g65g6