Proposal: Add prompt value to grouped_options_for_select

Hi!

grouped_options_for_select() has a prompt option to set the text of a default option for the select element but it doesn’t allow setting its value.

Allowing a prompt value would be useful in cases where the default option is not an empty string.

It could be set as a different option like prompt_value or we could also accept an array on prompt with [text, value] like [“Please select an option”, “default_value”].

Thoughts?

Thank you, Pedro Padron

The prompt option takes a boolean or a string. Here’s the docs:

Options:

:prompt - set to true or a prompt string. When the select element doesn’t have a value yet, this prepends an option with a generic prompt - “Please select” - or the given prompt string.

Does this help?

But it doesn’t allow setting a value. It will always be an empty string.

Using the same example from the documentation I’d like to generate something like this:

<option value="none">Please select an option</option>
<optgroup label="North America">
  <option value="US">United States</option>
  <option value="Canada">Canada</option>
</optgroup>
<optgroup label="Europe">
  <option value="Denmark">Denmark</option>
  <option value="Germany">Germany</option>
  <option value="France">France</option>
</optgroup>

Maybe allowing an array as well for prompt:

prompt: ["Please select an option", "none"]