.validate () не работает в jQuery Mobile
Я впервые использую плагин и метод .validate (). Теперь у меня есть форма, и каждый раз, когда я нажимаю кнопку отправки, она запускается без проверки формы. Вот мой код:
<form class="form d" method="post" action="">
<input type="text" name="searchtitle" id="searchtitle" placeholder="Enter the textbook's title">
<input type="text" name="searchauthor" id="searchauthor" placeholder="Enter the textbook's author">
<input type="text" name="searchpublisher" id="searchpublisher" placeholder="Enter the textbook's Publisher">
<input type="text" name="searchedition" id="searchedition" placeholder="Enter the textbook's edition">
<select name="searchuniversity" id="searchuniversity"></select>
<select name="searchuniversitycampus" id="searchuniversitycampus" ></select>
<input type="submit" id ="searchsubmit" name="searchsubmit" value="Search">
</form>
Затем у меня есть следующий Javascript:
$(document).on('pageinit',"#searchpage",
//this funciton will carry out the things we need to do to carry out our search
function(e)
{
e.preventDefault();
$(".form.d").validate({
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
comments: {
required: true,
minlength: 5,
nourl: true
}
},
messages: {
name: "Required Field",
email: "Valid Email Required",
comments: "Required Field + No URL's"
}
});
$("#searchsubmit").click(
function(e)
{
//Do a lot of processing here
});
});
Как я уже сказал, я очень новичок в проверке формата и использовании функции.
Вот является jsFiddle проблемы. Когда вы нажимаете на «Отправить» в скрипте, он выдает «привет», а затем выполняет проверку. Как это предотвратить? т.е. сначала проверить 1-й, а затем запустить функцию?