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

The options_for_select helper behaves weirdly #249

Closed
noelrappin opened this issue Dec 19, 2024 · 2 comments · May be fixed by #250
Closed

The options_for_select helper behaves weirdly #249

noelrappin opened this issue Dec 19, 2024 · 2 comments · May be fixed by #250

Comments

@noelrappin
Copy link

Given the following Phlex inside a component

include Phlex::Rails::Helpers::OptionsForSelect
include Phlex::Rails::Helpers::SelectTag

def view_template
  select_tag(:field, options_for_select(options, value))
end

The options render outside the select tag rather than inside.

@joeldrapper
Copy link
Collaborator

Thanks @noelrappin. As we discussed offline, this is going to be very tricky to fix due to the fact you can use this helper as a value or output.

Here are some workarounds that I believe will work for now.

  1. You could pass select_tag a block and use options_for_select as an output helper.
select_tag(:field) do
  options_for_select(options, value)
end
  1. You could capture the output of options_for_select.
select_tag(:field, capture { options_for_select(options, value) })
  1. You could register options_for_select as a value helper manually.
-include Phlex::Rails::Helpers::OptionsForSelect
+register_value_helper :options_for_select

@joeldrapper
Copy link
Collaborator

This will be fixed by #250, which will strongly encourage people to use options_for_select as an output helper rather than a value helper.

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

Successfully merging a pull request may close this issue.

2 participants