Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Simple form association is not being validated by rails clientside validation #453

sanandnarayan opened this Issue Dec 29, 2012 · 1 comment


None yet
2 participants

My version of rails is 3.2.9
client_side_validations (3.2.1)
client_side_validations-simple_form (2.0.1)
client_side_validations (> 3.2.0)
simple_form (
> 2.0.3)

I have a model User

class User < ActiveRecord::Base
  validates :goal, :presence => true, :on => :update
  belongs_to :goal, :class_name => Goal, :foreign_key => "goal_id"

and on the form i have

<%= simple_form_for @users,:remote => true, :url => registration_path(resource_name), :html => { :method => :put, :multipart => true }, :validate => true do |f| %>
 <%= f.association :goal,:label => "My overall goal is clearing", :input_html => {:class => 'goals'},:include_blank => true %>

But the rails client side validation does not pick up the validation on the association, it lets me fill in blank for goal.

Does rails client side validation gem work for simple form association?

The html page is

<div class="input select required"><label class="select required control-label" for="user_goal_id"><abbr title="required">*</abbr> My overall goal is clearing</label><select class="select required goals" id="user_goal_id" name="user[goal_id]" data-validate="true"><option value=""></option>
<option value="1">JEE Main</option>
<option value="2">JEE Advanced</option>
<option value="3">NEET</option>
<option value="4">CBSE 11 PCM</option>
<option value="5">CBSE 11 PCB</option>
<option value="6">CBSE 12 PCM</option>
<option value="7">CBSE 12 PCB</option></select></div>

I am getting the below script on my html page

if (window.ClientSideValidations == undefined) window.ClientSideValidations = {};
if (window.ClientSideValidations.forms == undefined) window.ClientSideValidations.forms = {};
window.ClientSideValidations.forms['edit_user_14'] = {
    "type": "SimpleForm::FormBuilder",
    "error_class": "error",
    "error_tag": "span",
    "wrapper_error_class": "field_with_errors",
    "wrapper_tag": "div",
    "wrapper_class": "input",
    "wrapper": "default",
    "validators": {
        "user[mobile_number]": {
            "format": [{
                "message": "should be 10 digits",
                "with": /^\d{10}$/i
        "user[profile_pic]": {
            "integrity": [{
                "message": "translation missing: en.activerecord.errors.models.user.attributes.profile_pic.integrity"
            "processing": [{
                "message": "translation missing: en.activerecord.errors.models.user.attributes.profile_pic.processing"
            "download": [{
                "message": "translation missing: en.activerecord.errors.models.user.attributes.profile_pic.download"
            "format": [{
                "message": "Wrong file format",
                "with": /\.(gif|jpeg|jpg|png)$/i,
                "allow_blank": true

bcardarella commented Dec 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment