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 #16

Closed
sanandnarayan opened this Issue Dec 30, 2012 · 4 comments

Comments

Projects
None yet
5 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"
  ...
end

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
            }]
        }
    }
};

nicohvi commented Apr 23, 2013

I have the same problem - cannot custom validate on <%= f.association %>

Same problem. How to validate association inputs such as select?

edooley commented Aug 12, 2014

Try validates :goal_id instead of validates :goal

Contributor

tagliala commented Jan 20, 2017

Hi,

thanks for reporting this.

I'm closing some old issues, hoping that this is not an issue anymore.

If it is still an issue, please provide a reproducible test case and I will consider reopening.

Contributing guidelines

@tagliala tagliala closed this Jan 20, 2017

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