Search code examples
ruby-on-railsclient-side-validation

Disable remote validations on client_side_validations gem


I'm quite pleased with the gem features. However, the current implementation of server-side validations uses synchronous ajax. Thus, I would like to know if these could be disabled application-wide, so I don't have exclude individual validators everywhere in my views, and also to be able to enable them later in case the implementation changes.


Solution

  • It seems it can easily be achieved with something like this:

    // seems that the name will change in a future release
    var validator = clientSideValidations || ClientSideValidations;
    // remove all remote handlers
    if (validator) validator.validators.remote = {};
    

    It should be run after rails.validations.js has been executed. If you are concerned in polluting the global namespace, just enclose it in a (function() { ... })() call.