Replies: 1 comment 1 reply
-
I don't have any experience with sequel-polymorphic, but basic use of optgroups would be: Forme::Form.new.input(:select, :optgroups=>{Notes: [['a', 1], ['b', 2]], Posts: [['c', 1], ['d', 3]]})
# <select><optgroup label="Notes"><option value="1">a</option><option value="2">b</option></optgroup>
# <optgroup label="Posts"><option value="1">c</option><option value="3">d</option></optgroup></select> I think the main problem you will have with this approach is you don't know when the form is submitted which type is submitted. You could do something like:
And parse the attachable type information out of the submitted value. That's kind of ugly, but should allow a single drop down to work. For this type of thing, selecting the attachable type first, then filling in the attachable options for that type is probably a better approach. That requires some Javascript, and it appears you want to avoid that approach. In general, I advise against using polymorphic associations. |
Beta Was this translation helpful? Give feedback.
-
i want to implement select dropdown with polymorphic field:
(how) can i do it using one dropdown?
thanks
(my real case has more sense but less clear)
Beta Was this translation helpful? Give feedback.
All reactions