Skip to content

Using custom validators

rubyconvict edited this page Aug 16, 2014 · 1 revision

ActiveModel:

validates :email, email: { disposable: true, blacklist: true, mx: true }

Add this at the bottom of your javascripts:

$(document).ready(function(event) {
    judge.eachValidators['email'] = (function(options, messages) {
                                      var validation = judge.pending();
                                      judge.get(judge.urlFor(this, 'email'), {
                                        success: function(status, headers, text) {
                                          validation.close(text);
                                        },
                                        error: function(status, headers, text) {
                                          validation.close(['Request error: ' + status]);
                                        }
                                      });
                                      return validation;
                                    });
});
Clone this wiki locally