-
Notifications
You must be signed in to change notification settings - Fork 403
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
use-associations-validations #787
base: main
Are you sure you want to change the base?
use-associations-validations #787
Conversation
1664e6a
to
d548184
Compare
@MichalRemis can you please paste the generated HTML code of a page showing the issue, as well as the ruby template? Maybe with both |
Sure: ruby:
HTML:
Problem with plain Rails radio/checkbox collections is that they don't have a wrapper around them like simple_form does. Regarding this PR. You can see validations for client_side_validations/src/main.js Lines 63 to 71 in c7468a6
it doesn't use client_side_validations/src/main.js Line 83 in c7468a6
box[colors] to apply validators correctly.
|
Thanks Got the need for different names we should do three things:
|
Look's like it normalizes input name for nested attributes https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
I don't think we may omit it safely for mainCSV, because JS validators, e.g.: client_side_validations/src/validators/local/absence_presence.js Lines 9 to 13 in c7468a6
aren't ready for checkboxes and would report false errors for association checkbox's inputs (not tested though). That's why I added SimpleForm::FormBuilder condition. It would be safe if you tweak validators to work with checkboxes, something like https://github.com/MichalRemis/client_side_validations-simple_form/blob/add-checkboxes-and-radios-support/src/validator_overrides/presence.js
If we can't check formbuilder's name and you have no other idea or won't implement working collection_checkboxes in main CSV, I could implement it in CSV_simple-form, but it would require a lot of code copy & pasting from main - I am not sure if that's a good idea. |
I need this change to make checkboxes/radiobuttons work in CSV-simple_form.
Currently in CSV validations are added to CSV hash (via
collection_check_boxes
/collection_radio_buttons
overrides). Events aren't attached to radiobuttons (filtered out). For checkboxes, events are attached but when JS validating, their validations are NOT applied because of special names of association checkbox inputs (e.g.user[:roles][]
). Not sure if this was an intention, but it is allright because standard presence validation wouldn't work for checkboxes anyway, and as I understand they are not going to be supported in main CSV.But to make collections work in CSV-simple_form I need to use (overridden) validations and therefore need to clean input names
user[:roles][]
->user[:roles]
. Couldn't do it in CSV-simple_form therefore updating it here in main. Maybe you have some better idea how to achieve this.