-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional validations break "required" field marking #322
Comments
This is intentional. At the moment you add conditional validation to an attribute, Simple Form requires you to explicitly pass required as executing the if/unless clauses on its own is very brittle. |
Any condition ( |
Excellent, thanks! |
Could you please elaborate on this? We have a local patch to simple_form that handles conditional validations for every type of block that can be legitimately passed to the ActiveRecord/ActiveModel validation. Anything that would break this functionality would also break the model validation itself, so by this definition, I consider our patch to be robust, and we are willing to take the time to turn it into a pull request. I feel that handling validations on the fly, but skipping conditional validations, leaves a fairly large gap in functionality as users will have to manually recreate the conditional validation logic for a given attribute in the view layer everywhere that such attributes are used with simple_form. This forces a violation of both DRY and basic encapsulation. Furthermore, we plan to put the functionality behind a configurable feature switch defaulted to off so as to be backwards compatible. |
@pivotal-casebook today users can put whatever they want in
I think we are overestimating the size of the gap here. ;) In the simplest scenario, we have this in our model:
Which means all you need in your view is:
In the most complex cases... we go back exactly to the point we were talking about: why do you have complex validations in your if/unless clauses? It is time to clean it up (and believe me, people do have crazy stuff in it). TL;DR: we want to avoid executing model code when generating the form. In any case, thanks a lot for the interest in improving Simple Form! |
Edit: perhaps I'm mixing up form building/presentation with validation. I need to look at client_side_validations. |
@rosskevin I believe you mean browser validations. Do you have it enabled in simple_form config file? SimpleForm.browser_validations = true |
SimpleForm.browser_validations is under initializers > simple_form > config.browser_validations. |
I am using conditional validations for a multi-step form, very much like this Railscast: http://railscasts.com/episodes/217-multistep-forms.
This causes the automatic "required" field marking to not function. The fields all end up with an "optional" class. The validations still work as expected upon form submission. Is this a known issue? Something I am doing wrong?
The text was updated successfully, but these errors were encountered: