Question

In simple_form if you supply an array to the disabled option...it will disable any association object created that is in the array. The same does not seem true for the readonly option.

this, for example, does what you would expect

f.association :items, collection: @items, as: :check_boxes, disabled: @used_items

however, this does not do what I would expect...

f.association :items, collection: @items, as: :check_boxes, readonly: @used_items

I set options using checkboxes, if the id is not passed back in the edit action...the record is deleted. Therefore, I can not use the disabled option. But, I can't seem to make this work using readonly.

Anyone know the trick??

Was it helpful?

Solution

readonly is not a valid attribute for checkboxes, see Can HTML checkboxes be set to readonly?

The solution suggested there is to have a disabled checkbox and a hidden input with the desired name to make sure the value is submitted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top