Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

client_side_validations 3.2.1, client_side_validation-simple_form 2.0.0 not work #434

Closed
jerryshen opened this Issue · 6 comments

2 participants

Jerry Shen Brian Cardarella
Jerry Shen

I'm using simple form with client side validations, when i add validate: true in form, it generates data-validate true for all fields (even that field is optional in model validations).

Really Need some help

fn = context[kind];
if (validators[kind]) {
_ref = validators[kind];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
validator = _ref[_i];
if (message = fn.call(context, element, validator)) {
valid = failElement(message);
break;
} 

TypeError: validators is undefined

Brian Cardarella
Owner

What version of Rails?

Jerry Shen

Sorry, for now it's ok. the error is gone, my rails version is 3.2.8
but I have another problem.

I have the following code

= simple_nested_form_for resource, url: url, validate: true do |f|
  = f.input :cusip, validate: { presence: true }

it seems like cusip doesn't trigger the presence validation

<input type="text" size="50" placeholder="i.e. 90000" name="deals_bond[cusip]" id="deals_bond_cusip" class="string optional" data-validate="true">

the html is right I think

Brian Cardarella
Owner

Is the presence validator on the model? Putting validate: { :presence => true } on the input doesn't add the validation

Jerry Shen

I see what you mean,
But if I have two forms with one model, one needs this presence validator, the other do not. how to handle this?
Thanks @bcardarella

Brian Cardarella
Owner

You can turn off the validation for the form that doesn't need it:

validate: { presence: false }

Please understand that this doesn't stop your model from running the validation on the server, it just tells ClientSideValidations to not include this particular validation rule for this one instance

Jerry Shen

That's what I want, for model it's easy to handle, just pass a hidden attribute

Thanks @bcardarella it really helps me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.