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
Custom validation context is missing #1318
Comments
What validation context? Could you give an example of how that should work? Links to Rails documentation? |
https://guides.rubyonrails.org/active_record_validations.html#on When rendering form, fields that has presence validators with :on option, are displayed without required label. |
(
validator_on.exclude?(:save)) && ( # there is no on: :save
(object.new_record? && validator_on.exclude?(:create)) # it is new record and there is no on :create
||
(!object.new_record? && validator_on.exclude?(:update) # it is existing object and there is no :update
)
) I see the logic as sound. And I see it tested. formtastic/spec/inputs/base/validations_spec.rb Lines 63 to 223 in 69a01f0
If it is not working for your case please try to contribute some example or a test case that shows what is wrong. |
I just stumbled upon the same thing. My case is that I have a
This will render the |
Ok, and how would you want the form to look like?
Or do it per input? Or for some inputs at ones? I think this could make sense if done properly, so it also makes it easier for you to hook into determining what is required. Maybe extracting the this: formtastic/lib/formtastic/inputs/base/validations.rb Lines 136 to 151 in 69a01f0
Into a method that is easily overridable in your custom form builder. |
Just stumbled into wanting this myself. Yes, the example syntax floated above by @mikz seems like it'd be great. |
Required labels missing when model has specific validation context, different from save update create.
formtastic/lib/formtastic/inputs/base/validations.rb
Line 138 in 69a01f0
As result, such validators are skipped. I think there should be some context option for semantic_form_for
The text was updated successfully, but these errors were encountered: