使用自定义方法的jQuery验证我无法提交表单 [英] Jquery Validation with custom method I can't submit form
问题描述
我正在使用带有自定义方法的jquery验证.我不知何故需要单击两次以提交表单.如果您在提交之前生成onblur事件,则该方法有效.
I am using jquery validation with custom method. Somehow I need to click twice to submit the form. If you generate onblur event before submit it works.
我已经设置了一个字段,然后单击下面带有验证的链接中的按钮.我设置为返回您输入的所有内容,但如果您不单击两次或生成onblur然后单击,则无法提交表单.我在这里做错什么了吗?
I have set up a field and click button in the following link with the validation. I set to return true anything you input but I can't submit a form if you don't click twice or generate onblur and click. Am i doing anything wrong here?
http://skoizumi.com/autocomplete/
jQuery.validator.addMethod("contractorName", function (value, element) {
console.log( '1');
console.log( element);
//$('#searchtext').autocomplete('close');
var result = false;
var contractorName = $("#searchtext" ).val();
//validating the specified field has a valid name
$.ajax({
type: "GET",
url: "/autocomplete/testdata.php",
dataType:"json",
async: false,
complete: function(){
},
success: function(msg)
{
console.log( msg);
result = true;
}
});
console.log( '2');
return result;
}, "Specified Contractor doesn't exist");
$("#myform").validate(
{
rules:{
searchtext: {
contractorName: true
}
},
onsubmit: false,
onkeyup: false
});
推荐答案
最后,我设法找到了解决方法.不知何故,当我将onfocusout设置为true时,我无法发布有效数据.通过添加自定义方法,您无需将服务器端更改为true/false,但可以决定完整的功能. http://skoizumi.com/autocomplete/index.html (如果您输入"European Nightjar")您可以通过一些错误提交表单.
Finally I managed to find work around. Somehow when I have onfocusout set to true I can't post valid data. With adding the custom method, you don't need to change the server side to have true/false but you can decide on complete function. http://skoizumi.com/autocomplete/index.html if you type in "European Nightjar" you can submit the form otherwise through some error.
这篇关于使用自定义方法的jQuery验证我无法提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!