Skip to content
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

Error messages gets displayed with each checkbox when working with collection_check_boxes #898

Open
1 task done
as-rikoouu opened this issue Nov 14, 2022 · 0 comments
Open
1 task done

Comments

@as-rikoouu
Copy link

as-rikoouu commented Nov 14, 2022

Steps to reproduce*

Code snippet added below

Expected behavior*

It would be ideal for the message to appear only once, maybe with the label and not with every checkbox.

Actual behavior*

When submitting the form without any selection, the message should appear once for each checkbox (please excuse the CSS)

Screenshot 2022-11-14 at 11 24 51 PM

System configuration*

Rails version: 6.1.4

Ruby version: 2.7.4

Client Side Validations version: latest

Code snippet from your model of the validations*

In the model, I have a custom method that checks and returns an error if no checkbox was selected. Basically, we don't want to show a default selected checkbox and want at least one to be selected by the user before the form can be submitted

serialize :shipping_carrier_type_ids, Array

validate :shipping_carrier_type_presence

def shipping_carrier_type_presence
  errors.add(:shipping_carrier_type_ids, "Select at least one Shipping Carrier Type") if shipping_carrier_type_ids.reject(&:empty?).blank?
end

The whole form code from your template*

<%= f.collection_check_boxes :shipping_carrier_type_ids, ShippingCarrierType.all, :id, :name, {}, {class: 'form-control bb-field'} %>

The resulting HTML*

Screenshot 2022-11-14 at 11 24 51 PM

Browser's development console output*

  • I confirm that my browser's development console output does not contain errors

Additional JavaScript Libraries*

If your issue depends on other JavaScript libraries, please list them here. E.g: Bootstrap Modal v3.3.7, jQuery UI Datepicker 1.12.4.

Repository demostrating the issue

Debugging CSV issues is a time consuming task. If you want to speed up things, please
provide a link to a repository showing the issue.


* Failure to include this requirement may result in the issue being closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant