nathanvda / cocoon

Dynamic nested forms using jQuery made easy; works with formtastic, simple_form or default forms
http://github.com/nathanvda/cocoon
MIT License
3.08k stars 382 forks source link

`link_to_remove` does not remove elements from DOM, and thus does not support clearing out enum array #624

Open anaulin opened 2 years ago

anaulin commented 2 years ago

@nathanvda following up on https://github.com/nathanvda/cocoon/issues/568#issuecomment-1189843826 in a separate issue as requested.

In my case, I want to allow a user to add or remove items to a column that is an array of enum[1].

Cocoon's link_to_remove does remove the item from the form, but it leaves the array item in the DOM (just hidden), so the array doesn't get properly updated on form save (if this was an association, the _destroy attribute would update it correctly, but that doesn't work for an array field)

There is also more manual stuff that I need to do in my case, since I am letting the user pick from a drop-down of values to add, which then have to be disabled/re-enabled in the dropdown when they get added or removed. To give you an idea of how I want my form to behave, here it is with my own hand-written "remove" code: dynamic-nested-form-enum-array


[1]: column is defined as secondary_roles public.user_role[] DEFAULT '{}'::public.user_role[] NOT NULL