1000hz / bootstrap-validator

A user-friendly HTML5 form validation jQuery plugin for Bootstrap 3
http://1000hz.github.io/bootstrap-validator
MIT License
2.38k stars 1.07k forks source link

Handling ajax responses for custom validation #382

Open mark47 opened 8 years ago

mark47 commented 8 years ago

I noticed some previous discussion of custom error handling when an ajax call is involved, but am having trouble getting it to work. Is there a way to employ $deferred or $promises?

My particular issue - using @.ajax to check whether an email address is already in our database. I want to return whether it is unique. Validator always returns something before my ajax is complete.

1000hz commented 8 years ago

Sorry, it's not possible yet. One of the next big improvements I want to make is to support returning a promise/deferred from a validator.

1000hz commented 8 years ago

In your case though, you might be able to use data-remote to check against a validation endpoint

mark47 commented 8 years ago

Thanks @1000hz for the quick response. I played around with your suggestion to use data-remote -- it's definitely the right direction, but the API (which alas I don't control) doesn't quite return data in a proper format for the validator to process.

Anyway, glad it's on the roadmap going forward. Thanks for all your work on this!

garygreen commented 8 years ago

@mark47 just a lil plug, if you want to checkout dominar.js it has support for ajax validation the kind your looking for :)