I have a select tag with 2 options :
select_tag :type, options_for_select("<option value = 'produit1'>Produit1</option><option value = 'Produit2'>Produit2</option>", params[:product]), id: "different_option_value_html", onchange: "this.form.submit();", include_blank: "Which products ?"
When one of this options are selected, the form is automatically submit. I would like to keep the params in first position. I mean visible without clicking on the select, at the place of "which products".
The select tag in HTML is used to create a dropdown list of options that can be selected. The option tag contains the value that would be used when selected. The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute.
var selectbox_defaultOption = document. querySelector("#some_dropdown option[selected]");
I finally change the syntax and it works fine using :options_for_select(:collection, :selected)
So there is my code now :
= select_tag :product, options_for_select(["Product1", "Product2"], params[:product]), id: "different_option_value_html", onchange: "this.form.submit();", include_blank: "Which product ?"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With