vicb/bsmSelect

in a rails habtm, can't remove final item?

davev opened this issue · 5 comments

don't know if this is BSM or Rails, but if there is only one associated record, if you click "remove" and save the form, the corresponding record in the join table is NOT removed. works perfectly until you get down to the edge case of only one record left. also works correctly if you remove that record and add another before saving. ideas? tia.

vicb commented

Please try to sort out if this this is a bsmSelect defect, provide a standalone script showing the defect and I'll look into this.

it's not BSM. i've duplicated the same behavior in Rails, (with Formtastic) using a regular multi-select dropdown. thanks.

figured out the answer - it's because multiselects aren't submitted by browser if no options are selected.

vicb commented

it's good you have solved your issue and thanks for giving feedback.

Yes, it's a "native behavior". But you can solve this problem easily.

When none of the check boxes are selected, nothing is submitted. So you must add this hidden field at the end of form (example)

<%= hidden_field_tag "user[company_ids][]" %>

See more at this StackOverflow issue.