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

Rails-style options for select #1436

Merged
merged 3 commits into from Oct 8, 2013
Merged

Rails-style options for select #1436

merged 3 commits into from Oct 8, 2013

Conversation

ujifgc
Copy link
Member

@ujifgc ujifgc commented Oct 8, 2013

ref #872

opts = {
  "Friends" => ["Yoda",["Obiwan",2,:magister=>'no'],:lame=>'yes'],
  "Enemies" => [["Palpatine","Palpatine",:scary=>'yes',:old=>'yes'],["Darth Vader",3,:disabled=>true]]
}
actual_html = select_tag( 'name', :grouped_options => opts, :disabled_options => [2], :selected => ['Yoda'] )

=>

<select name="name">
<optgroup label="Friends" lame="yes">
<option value="Yoda" selected="selected">Yoda</option>
<option value="2" magister="no" disabled="disabled">Obiwan</option>
</optgroup>
<optgroup label="Enemies">
<option value="Palpatine" scary="yes" old="yes">Palpatine</option>
<option value="3" disabled="disabled">Darth Vader</option>
</optgroup>
</select>

If additional API is acceptable, we can close #872

Also I would like to drop confusing API with slipping booleans into array of options to disable them like this:

opts = {
        "Friends" => ["Yoda",["Obiwan",2,true]] # I'm confused, my head is spinning

@@ -739,6 +739,18 @@ def protect_from_csrf; false; end
assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled') { actual_html }
end

should "display select tag with grouped options for a rails-style attribute hash" do
opts = {
"Friends" => ["Yoda",["Obiwan",2,:magister=>'no'],:lame=>'yes'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add braces for hash in array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, 1.8.7 trips on that.

@namusyaka
Copy link
Contributor

Awesome!

namusyaka added a commit that referenced this pull request Oct 8, 2013
Rails-style options for select, closes #872
@namusyaka namusyaka merged commit c7dd679 into master Oct 8, 2013
@ujifgc ujifgc deleted the rails-style-select branch October 8, 2013 09:52
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 this pull request may close these issues.

disabled attribute for select_tag options
2 participants