欧芹远程多输入值验证
问题描述:
我需要在欧芹远程中使用两个输入字段进行验证。即欧芹远程多输入值验证
$('#user-name').parsley().addAsyncValidator('remotevalidator',remotevalidationfunction,'validation-url.htm');
上述示例取得用户名的值,并将其作为参数传递给validation-url.htm。 我需要传递另一个输入字段的值location
。
请让我知道这可以在欧芹远程完成。
答
我不认为你可以做到这一点与远程验证。解决问题的最佳方法是使用$.ajax
和addValidator
:
<input type="text" name="username" data-parsley-username />
<input type="text" name="location" id="location" />
<script>
window.ParsleyValidator
.addValidator('username', function (value, requirement) {
var response = false,
location = $("#location").val();
$.ajax({
url: "validation-url.htm",
data: {username: value, location: location},
dataType: 'json',
type: 'get',
async: false,
success: function(data) {
// if you send something from the server, you might want to
// do some verification here
response = true;
},
error: function() {
response = false;
}
});
return response;
}, 32)
.addMessage('en', 'username', 'Username is invalid.');
</script>