mardi 26 juin 2018

collection_check_boxes disable checked checkboxes

i have a collection of checkboxes (collection_check_boxes) inside a form_group. i need to disable all checkboxes that are checked on page load. The collection looks like this:

f.collection_check_boxes :should_create, Student.all, :id, :name, checked: @teacher.try(:class).map(&:student_id), disabled: @teacher.try(:class).map(&:student_id), label: "Create class", include_hidden: false

where the collection is the students and the checked students are those that are already in the teacher's class which returns [1, 2, 4]. However, whereas checked: [1,2,4] results in those three checkboxes being checked, disabled: [1,2,4] results in every checkbox being disabled, rather than just those three. How can I disable just those checkboxes?

Note: once a student has been checked you cannot uncheck that student (ie: remove the student from the class join table on the backend)




Aucun commentaire:

Enregistrer un commentaire