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

Should select show a prompt when its attribute is false? #51602

Open
mrj opened this issue Apr 18, 2024 · 8 comments · May be fixed by #51605
Open

Should select show a prompt when its attribute is false? #51602

mrj opened this issue Apr 18, 2024 · 8 comments · May be fixed by #51605

Comments

@mrj
Copy link
Contributor

mrj commented Apr 18, 2024

At the moment the attribute select helper adds the empty prompt option if the attribute is blank. However blank? is true for false, meaning that the prompt will still be shown if a boolean attribute has been set to the valid value of false rather than its initial null.

Should the ActionView line linked above instead be: if value != false && value.blank? && options[:prompt]?

@rafaelfranca
Copy link
Member

Maybe, but this is a change in behavior so it needs to be well justified. Can you expand why the current behavior doesn't work for you giving a real example?

@mrj
Copy link
Contributor Author

mrj commented Apr 18, 2024

Rafael, I'm just finding that the prompt persists even when a boolean option has been selected and saved. I expected the prompt to disappear as it's no longer needed because the user understands the choices. No prompt also makes the size of this select much more compact and neater.

@rafaelfranca
Copy link
Member

Makes sense to me. Do you want to open a pull request?

mrj added a commit to mrj/rails that referenced this issue Apr 19, 2024
@mrj mrj linked a pull request Apr 19, 2024 that will close this issue
@justinko
Copy link
Contributor

This behavior has existed forever, and I believe it's correct.

In the case of a boolean column, as an example, you may want to force the user to choose the truthy value to proceed. A checkbox is probably more appropriate but some people prefer to use select.

What I've done in the past is simply prompt: value.nil?

@mrj
Copy link
Contributor Author

mrj commented Apr 19, 2024

Thank you Justin. In my case either a select or two mutually-exclusive buttons scripted to a hidden radio, checkbox, or field is most appropriate.

If this change won't proceed, I'll take your suggestion and change from

prompt: 'Choose Voice Gender' 

to

prompt: ('Choose Voice Gender' if @record.attribute.nil?)

@mrj
Copy link
Contributor Author

mrj commented Apr 19, 2024

Justin, what's your argument for the current behaviour being correct (rather than just traditional). Is there a circumstance where the changed behaviour would be wrong or unexpected (PLOS-wise)?

@justinko
Copy link
Contributor

I can't think of a circumstance where it would be wrong, but you do remove the ability to have false with prompt. Maybe that's okay? I'm just skeptical why the current behavior has existed for 12 years.

@justinko
Copy link
Contributor

I was curious and looked at other frameworks and libraries. For the ones that actually have a prompt option, they allow/require full control over whether it's utilized or not (equivalent in Rails would be removing value.blank?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants