How to set selected option in select?
#68
Unanswered
janpeterka
asked this question in
Q&A
Replies: 1 comment
|
Looking into code, I found this: # rails/components/select.rb
def options(*collection)
map_options(collection).each do |key, value|
option(selected: field.value == key, value: key) { value }
end
endFrom that I guess only way is to set the attribute value on given model. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm probably missing something quite obvious, but I'm unable to set selected option in my form.
I tried doing it like this:
Field(:chapter_style_name).select(*model.used_styles.to_a, selected: default_chapter_style_name), and also triedvalueanddefault, and nothing does the trick.Thanks for your help!
All reactions