Reputation: 569
I use bootstrap-validator(http://1000hz.github.io/bootstrap-validator) and need display error message if ajax request is successful and has status 'ok'.(customer exists so to speak).
How can I return on ajax request and get it working with validator? Here is current code:
$('form').validator({
custom: {
business: function($el) {
var input_value = $el.val();
if(input_value.length > 5){
var result2;
$.ajax({
type: 'GET',
url: '/customers/'+input_value,
dataType: 'json',
success: function(data){
(data.status == 'ok' ? $(".nahtavad").prop('disabled', true) : $(".nahtavad").prop('disabled', false));
// if i return here it does nothing and does not display error.
return 'This customer exits'
}else {
$(".nahtavad").prop('disabled', false);
}
},
error: function (err) {
$("input[type='submit']").prop('disabled', false);
$(".nahtavad").prop('disabled', false);
}
});
}
}
}
});
Upvotes: 0
Views: 432
Reputation: 569
It's was not possible to return on ajax request so, added this check after length control and now it's working as should be:
if($(".nahtavad").is('[disabled]') === true){
return 'Error';
}
Upvotes: 0