Commit f38a825d6e9abe5aa5a6e603cb76318975ec3f7a
Committed by
Daniela Feitosa
1 parent
eb7e3c1f
Exists in
master
and in
28 other branches
Show title in select options
(ActionItem1656)
Showing
5 changed files
with
31 additions
and
3 deletions
Show diff stats
app/helpers/forms_helper.rb
... | ... | @@ -111,6 +111,18 @@ module FormsHelper |
111 | 111 | )) |
112 | 112 | end |
113 | 113 | |
114 | + def options_for_select_with_title(container, selected = nil) | |
115 | + container = container.to_a if Hash === container | |
116 | + | |
117 | + options_for_select = container.inject([]) do |options, element| | |
118 | + text, value = option_text_and_value(element) | |
119 | + selected_attribute = ' selected="selected"' if option_value_selected?(value, selected) | |
120 | + options << %(<option title="#{html_escape(text.to_s)}" value="#{html_escape(value.to_s)}"#{selected_attribute}>#{html_escape(text.to_s)}</option>) | |
121 | + end | |
122 | + | |
123 | + options_for_select.join("\n") | |
124 | + end | |
125 | + | |
114 | 126 | protected |
115 | 127 | def self.next_id_number |
116 | 128 | if defined? @@id_num | ... | ... |
app/views/box_organizer/_article_block.rhtml
1 | - | |
1 | +<div class='article-block-edition'> | |
2 | 2 | <% if @block.box.owner.kind_of?(Environment) and @block.box.owner.portal_community.nil? %> |
3 | 3 | <p id='no_portal_community'> |
4 | 4 | <%= _("You don't have an community defined as the portal community. Define it before use this block properly.") %> |
5 | 5 | </p> |
6 | 6 | <% else %> |
7 | 7 | <% articles = @block.available_articles.select {|article| !article.folder? } %> |
8 | - <%= select('block', 'article_id', articles.map {|item| [ item.path, item.id]}) %> | |
8 | + <%= select_tag('block[article_id]', options_for_select_with_title(articles.map {|item| [item.path, item.id]})) %> | |
9 | 9 | <% end %> |
10 | +</div> | ... | ... |
public/stylesheets/application.css
... | ... | @@ -3944,6 +3944,15 @@ h1#agenda-title { |
3944 | 3944 | margin: 5px 0px 5px 160px; |
3945 | 3945 | } |
3946 | 3946 | |
3947 | +.controller-profile_design .article-block-edition select, | |
3948 | +.controller-profile_design .article-block-edition option { | |
3949 | + width: 300px; | |
3950 | +} | |
3951 | + | |
3952 | +.controller-profile_design .article-block-edition option { | |
3953 | + overflow-x: hidden; | |
3954 | +} | |
3955 | + | |
3947 | 3956 | /* ==> public/stylesheets/controller_profile_editor.css <== */ |
3948 | 3957 | |
3949 | 3958 | .controller-profile_editor .categorie_box .button { | ... | ... |
test/functional/environment_design_controller_test.rb
... | ... | @@ -70,7 +70,7 @@ class EnvironmentDesignControllerTest < Test::Unit::TestCase |
70 | 70 | article.expects(:path).returns('some_path') |
71 | 71 | article.expects(:id).returns(1) |
72 | 72 | get :edit, :id => l.id |
73 | - assert_tag :tag => 'select', :attributes => { :id => 'block_article_id' } | |
73 | + assert_tag :tag => 'select', :attributes => { :id => 'block[article_id]' } | |
74 | 74 | end |
75 | 75 | |
76 | 76 | should 'be able to edit ArticleBlock without portal community' do | ... | ... |
test/unit/forms_helper_test.rb
... | ... | @@ -4,6 +4,7 @@ class FormsHelperTest < Test::Unit::TestCase |
4 | 4 | |
5 | 5 | include FormsHelper |
6 | 6 | include ActionView::Helpers::TagHelper |
7 | + include ActionView::Helpers::FormOptionsHelper | |
7 | 8 | |
8 | 9 | should 'wrapper required fields in <span class=required-field>' do |
9 | 10 | content = required('<input type=text name=test>') |
... | ... | @@ -20,6 +21,11 @@ class FormsHelperTest < Test::Unit::TestCase |
20 | 21 | assert_tag_in_string content, :tag => 'label', :content => 'highlighted', :attributes => {:class => 'pseudoformlabel'} |
21 | 22 | end |
22 | 23 | |
24 | + should 'show title for option in select' do | |
25 | + content = options_for_select_with_title({'option_value' => 'option_title'}) | |
26 | + assert_tag_in_string content, :tag => 'option', :attributes => {:title => 'option_value'} | |
27 | + end | |
28 | + | |
23 | 29 | protected |
24 | 30 | |
25 | 31 | def _(text) | ... | ... |