Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new select_prompt method #1027

Closed
jwoertink opened this issue Mar 5, 2020 · 3 comments · Fixed by #1124
Closed

Add a new select_prompt method #1027

jwoertink opened this issue Mar 5, 2020 · 3 comments · Fixed by #1124
Labels
easy/high impact feature request A new requested feature / option

Comments

@jwoertink
Copy link
Member

If you're using select_tag and rending all your options, there's no easy way to currently set your prompt. It would be neat to have a select_prompt method so we don't just bloat the current options_for_select with options.

select(op.opts) do
  select_prompt("Select your option")
  options_for_select(op.opts, my_options)
end

My thought is this method would only generate:

<option value="">Select your option</option>

If your prompt option is first, then it will display that, unless you have a selected option. The selected option would get set from your options_for_select, and then it would default to that.

Another way could be to pass in the attribute so you could not render the field if there's a value, but then you'd never be able to "unselect" your value....

select_prompt(op.opts, "Select your option")
@jwoertink jwoertink added easy/high impact feature request A new requested feature / option labels Mar 5, 2020
@paulcsmith
Copy link
Member

paulcsmith commented Mar 5, 2020 via email

@jwoertink
Copy link
Member Author

ah! Yeah, I guess that's true too. You might not want someone to select a blank value if the record already exists. Good thinking!

@bdtomlin
Copy link
Contributor

bdtomlin commented Mar 8, 2020

This would be nice. I frequently use multiple options_for_selects.

This took me some time to figure out initially because I was expecting a prompt argument or something similar. It might not hurt to mention this way in the docs for when there are more complex requirements.

options_for_select @save_user.manager_id, [{"", ""}]
options_for_select @save_user.manager_id, @manager_options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy/high impact feature request A new requested feature / option
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants