Select/4 without form

Hi folks,

Does anybody know how to pass value from select/4 (not connected to any form) as a parameter to path in link?
To get: query_string: “group_id=-1”

The case: on first page choose value in select list, pass it to second page by menu_path, second page behavior depands from this value.

I tried, but it does not work:

<%= select :group, :group_id, @groups, class: "form-control", prompt: "groups", selected: -1 %>
<%= link "add", to: menu_path(@conn, :new, @menu, group_id: group_id), class: "btn btn-success btn-xs" %>

Appreciate your help.

Select as specified in HTML does need an enclosing form as far as I remember. So it does not make sense to use it without one…

1 Like

With html5 that’s not the case. There aren’t restrictions on possible parents and there’s even the form attribute to link the select to a form elsewhere in the markup.

And they said HTML5 made things better…

But this is actually a nice to know and might come in handy in a (side) project of mine…

Yeah, HTML5 is a bit backwards in many ways, I was really rooting for XHTML(2)…

There is for tables, which is highly irritating with custom elements…

I’ve just looked at the mdn docs for that. The most obvious thing to note is surely that inputs no longer need to be nested within a form tag, but can be related to a form otherwise as well.

1 Like