DavyJonesLocker / DavyJonesLocker/client_side_validations

Error messages gets displayed with each checkbox when working with collection_check_boxes

Open
#898 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.7k
Forks
395
Avg merge
3m
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior with Rails collection_check_boxes, the shipping_carrier_type_ids validation, and the provided form snippet. Trace how the client-side validation error is attached to each checkbox. Done means the custom error appears once for the collection, such as beside its label, rather than once per checkbox.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.