Hello, I have a problem creating custom validation and returning the error if ajax request status is 'ok'. Basically I need display error if ajax request returns status == ok. This means a customer with this personal ID. exists and this should disable submit button and dispaly error message.
I been trying to get this work for days.
Thank you in advance! :)
Here is my current code:
$('form').validator({
custom: {
customer: function($el) {
var input_value = $el.val();
if(input_value.length => 10){
$.ajax({
type: 'GET',
url: '/users/'+input_value,
dataType: 'json',
success: function(data){
if(data.status == 'ok'){
//validation
$("#user_login").attr("type", "hidden");
$("#user_email").attr("type", "hidden");
$("#user_password").attr("type", "hidden");
$("#user_password_confirmation").attr("type", "hidden");
$('form').validator('update');
$('form').validator('validate');
// if exists return here, it does nothing and does not display error.
return 'This customer exits'
else
$(".nahtavad").prop('disabled', false);
}
}else {
$(".nahtavad").prop('disabled', false);
}
},
error: function (err) {
$("input[type='submit']").prop('disabled', false);
$(".nahtavad").prop('disabled', false);
}
});
}
}
}
});
HTML <input class="form-control isikukood hide-controls" id="isikukood" data-error="can't be blank" pattern="^[A-z0-9-]+" data-pattern-error="These characters are not allowed!" required="required" data-customer="" data-customer-error="This user already exits!" name="user[personal_code]" type="text">
Hello, I have a problem creating custom validation and returning the error if ajax request status is 'ok'. Basically I need display error if ajax request returns status == ok. This means a customer with this personal ID. exists and this should disable submit button and dispaly error message.
I been trying to get this work for days.
Thank you in advance! :) Here is my current code:
HTML
<input class="form-control isikukood hide-controls" id="isikukood" data-error="can't be blank" pattern="^[A-z0-9-]+" data-pattern-error="These characters are not allowed!" required="required" data-customer="" data-customer-error="This user already exits!" name="user[personal_code]" type="text">