Search code examples
jqueryruby-on-railsrubyvalidationsimple-form

Client side validation in rails? Is there no hope?


Im using simple_form which im beginning to regret, simply (pun) because of the amount of work around you have to do to get anything done right.

Im using the latest verson of rails 4 and everythings going well except for client side validation on all of my forms.

I cant get Jquery validate to work and every single gem i can find is no longer supported.

This seems like such an easy problem to solve. Can anyone point me in the right direction?


Solution

  • The issue was with the asset pipeline and the order it pulled my .js files together.

    I simply made controller .js files for each controller that utilizes validation and matched my model validations in java script.

    For example in 'assets/javascripts/messages.js'

    $('#message-form').validate({
    debug: true,
    rules: {
        'message[name]': {required: true, name: true},
        'message[sub]': {required: true},
        'message[notes]': {required: true}
    }});
    

    After that Rails is smart enough to do the rest.

    You will have to make sure jquery validations is in the application.js reference