Commit d9cfd63a4e55813770d3360b62a63a3f8c4b6e0a
1 parent
55c936a8
Exists in
master
and in
28 other branches
ActionItem182: mandatory fields in forms must be highlighted
highlight all required fields in noosfero forms
Showing
16 changed files
with
52 additions
and
26 deletions
Show diff stats
app/helpers/forms_helper.rb
@@ -96,6 +96,10 @@ module FormsHelper | @@ -96,6 +96,10 @@ module FormsHelper | ||
96 | observe_field( state_id, :update => city_id, :function => "new Ajax.Updater(#{city_id.inspect}, #{url_for(:controller => 'search', :action => 'cities').inspect}, {asynchronous:true, evalScripts:true, parameters:'state_id=' + value}); $(#{city_id.inspect}).innerHTML = '<option>#{_('Loading...')}</option>'", :with => 'state_id') | 96 | observe_field( state_id, :update => city_id, :function => "new Ajax.Updater(#{city_id.inspect}, #{url_for(:controller => 'search', :action => 'cities').inspect}, {asynchronous:true, evalScripts:true, parameters:'state_id=' + value}); $(#{city_id.inspect}).innerHTML = '<option>#{_('Loading...')}</option>'", :with => 'state_id') |
97 | end | 97 | end |
98 | 98 | ||
99 | + def required(content) | ||
100 | + content_tag('span', content, :class => 'required-field') | ||
101 | + end | ||
102 | + | ||
99 | protected | 103 | protected |
100 | def self.next_id_number | 104 | def self.next_id_number |
101 | if defined? @@id_num | 105 | if defined? @@id_num |
app/views/account/_signup_form.rhtml
@@ -3,20 +3,20 @@ | @@ -3,20 +3,20 @@ | ||
3 | :html => { :help=>_('Fill all this fields to join in this environment. <p/> If you forgot your password, do not create a new account, click on the "<b>I forgot my password!</b>" link. ;-)'), :id => 'profile-data' | 3 | :html => { :help=>_('Fill all this fields to join in this environment. <p/> If you forgot your password, do not create a new account, click on the "<b>I forgot my password!</b>" link. ;-)'), :id => 'profile-data' |
4 | } do |f| -%> | 4 | } do |f| -%> |
5 | 5 | ||
6 | -<%= f.text_field :login, | ||
7 | - :onchange => 'this.value = convToValidLogin( this.value )' %> | 6 | +<%= required f.text_field(:login, |
7 | + :onchange => 'this.value = convToValidLogin( this.value )') %> | ||
8 | <small><%= help %></small> | 8 | <small><%= help %></small> |
9 | 9 | ||
10 | -<%= f.text_field :email, | ||
11 | - :help => help=_('We\'ll send you an e-mail to validate your registration.') %> | 10 | +<%= required f.text_field(:email, |
11 | + :help => help=_('We\'ll send you an e-mail to validate your registration.')) %> | ||
12 | <small><%= help %></small> | 12 | <small><%= help %></small> |
13 | 13 | ||
14 | -<%= f.password_field :password, | ||
15 | - :help => help=_('Choose a password that you can remember easily.') %> | 14 | +<%= required f.password_field(:password, |
15 | + :help => help=_('Choose a password that you can remember easily.')) %> | ||
16 | <small><%= help %></small> | 16 | <small><%= help %></small> |
17 | 17 | ||
18 | -<%= f.password_field :password_confirmation, | ||
19 | - :help => help=_('To confirm, repeat your password.') %> | 18 | +<%= required f.password_field(:password_confirmation, |
19 | + :help => help=_('To confirm, repeat your password.')) %> | ||
20 | <small><%= help %></small> | 20 | <small><%= help %></small> |
21 | 21 | ||
22 | <%= icaptcha_field() %> | 22 | <%= icaptcha_field() %> |
app/views/categories/_form.rhtml
@@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
12 | 12 | ||
13 | <%= select_color_for_category %> | 13 | <%= select_color_for_category %> |
14 | 14 | ||
15 | - <%= f.text_field 'name' %> | 15 | + <%= required f.text_field('name') %> |
16 | 16 | ||
17 | <% f.fields_for :image_builder, @category.image do |i| %> | 17 | <% f.fields_for :image_builder, @category.image do |i| %> |
18 | <%= file_field_or_thumbnail(_('Image:'), @category.image, i) %> | 18 | <%= file_field_or_thumbnail(_('Image:'), @category.image, i) %> |
app/views/cms/_event.rhtml
1 | <%# TODO add Textile help here %> | 1 | <%# TODO add Textile help here %> |
2 | <%= render :file => 'shared/tiny_mce' %> | 2 | <%= render :file => 'shared/tiny_mce' %> |
3 | 3 | ||
4 | -<%= f.text_field('name', :size => '64') %> | 4 | +<%= required f.text_field('name', :size => '64') %> |
5 | 5 | ||
6 | <%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> | 6 | <%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> |
7 | 7 |
app/views/cms/_folder.rhtml
@@ -2,6 +2,6 @@ | @@ -2,6 +2,6 @@ | ||
2 | <%# TODO add Textile help here %> | 2 | <%# TODO add Textile help here %> |
3 | <%= render :file => 'shared/tiny_mce' %> | 3 | <%= render :file => 'shared/tiny_mce' %> |
4 | 4 | ||
5 | -<%= f.text_field('name', :size => '64') %> | 5 | +<%= required f.text_field('name', :size => '64') %> |
6 | 6 | ||
7 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64)) %> | 7 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64)) %> |
app/views/cms/_rss_feed.rhtml
1 | -<%= f.text_field :name %> | 1 | +<%= required f.text_field(:name) %> |
2 | 2 | ||
3 | -<%= labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> | 3 | +<%= required labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> |
4 | 4 | ||
5 | <%= labelled_form_field(_('Use as item description:'), select(:article, :feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %> | 5 | <%= labelled_form_field(_('Use as item description:'), select(:article, :feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %> |
6 | 6 |
app/views/cms/_textile_article.rhtml
app/views/cms/_tiny_mce_article.rhtml
1 | 1 | ||
2 | <%= render :file => 'shared/tiny_mce' %> | 2 | <%= render :file => 'shared/tiny_mce' %> |
3 | 3 | ||
4 | -<%= f.text_field('name', :size => '64') %> | 4 | +<%= required f.text_field('name', :size => '64') %> |
5 | 5 | ||
6 | <%= f.text_area('body', :cols => 40, :style => 'width:99%') %> | 6 | <%= f.text_area('body', :cols => 40, :style => 'width:99%') %> |
7 | 7 |
app/views/cms/_uploaded_file.rhtml
1 | -<%= labelled_form_field(_("Select the file you want to upload (max size %s).") % UploadedFile.max_size.to_humanreadable, file_field(:article, :uploaded_data)) %> | 1 | +<%= required labelled_form_field(_("Select the file you want to upload (max size %s).") % UploadedFile.max_size.to_humanreadable, file_field(:article, :uploaded_data)) %> |
2 | 2 | ||
3 | <%= labelled_form_field(_('Describe this file:'), text_area(:article, :abstract)) %> | 3 | <%= labelled_form_field(_('Describe this file:'), text_area(:article, :abstract)) %> |
app/views/contact/new.rhtml
@@ -6,11 +6,11 @@ | @@ -6,11 +6,11 @@ | ||
6 | 6 | ||
7 | <%= hidden_field_tag 'contact[target_id]', profile.id %> | 7 | <%= hidden_field_tag 'contact[target_id]', profile.id %> |
8 | <%= hidden_field_tag 'contact[requestor_id]', (logged_in? ? current_user.person.id : nil) %> | 8 | <%= hidden_field_tag 'contact[requestor_id]', (logged_in? ? current_user.person.id : nil) %> |
9 | - <%= f.text_field :subject %> | ||
10 | - <%= f.text_field :email %> | 9 | + <%= required f.text_field(:subject) %> |
10 | + <%= required f.text_field(:email) %> | ||
11 | <%= f.text_field :city_and_state %> | 11 | <%= f.text_field :city_and_state %> |
12 | <%= f.text_field :phone %> | 12 | <%= f.text_field :phone %> |
13 | - <%= f.text_area :message, :rows => 5 %> | 13 | + <%= required f.text_area(:message, :rows => 5) %> |
14 | 14 | ||
15 | <%= submit_button(:send, _('Send')) %> | 15 | <%= submit_button(:send, _('Send')) %> |
16 | 16 |
app/views/content_viewer/_comment_form.rhtml
@@ -21,8 +21,8 @@ | @@ -21,8 +21,8 @@ | ||
21 | 21 | ||
22 | <% unless logged_in? %> | 22 | <% unless logged_in? %> |
23 | 23 | ||
24 | - <%= labelled_form_field(_('Name'), text_field(:comment, :name)) %> | ||
25 | - <%= labelled_form_field(_('e-mail'), text_field(:comment, :email)) %> | 24 | + <%= required labelled_form_field(_('Name'), text_field(:comment, :name)) %> |
25 | + <%= required labelled_form_field(_('e-mail'), text_field(:comment, :email)) %> | ||
26 | <%= icaptcha_field() %> | 26 | <%= icaptcha_field() %> |
27 | 27 | ||
28 | <p> | 28 | <p> |
@@ -31,8 +31,8 @@ | @@ -31,8 +31,8 @@ | ||
31 | 31 | ||
32 | <% end %> | 32 | <% end %> |
33 | 33 | ||
34 | - <%= labelled_form_field(_('Title'), text_field(:comment, :title)) %> | ||
35 | - <%= labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %> | 34 | + <%= required labelled_form_field(_('Title'), text_field(:comment, :title)) %> |
35 | + <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %> | ||
36 | <% button_bar do %> | 36 | <% button_bar do %> |
37 | <%= submit_button('add', _('Post comment')) %> | 37 | <%= submit_button('add', _('Post comment')) %> |
38 | <% end %> | 38 | <% end %> |
app/views/manage_products/_form.rhtml
1 | <%= error_messages_for :product %> <br/> | 1 | <%= error_messages_for :product %> <br/> |
2 | 2 | ||
3 | <% form_for :product, @product, :html => {:multipart => true }, :url => {:action => mode} do |f| %> | 3 | <% form_for :product, @product, :html => {:multipart => true }, :url => {:action => mode} do |f| %> |
4 | - <%= display_form_field( _('Name:'), f.text_field(:name) ) %> | 4 | + <%= required display_form_field( _('Name:'), f.text_field(:name) ) %> |
5 | <%= display_form_field( _('Price:'), f.text_field(:price) ) %> | 5 | <%= display_form_field( _('Price:'), f.text_field(:price) ) %> |
6 | <%= display_form_field( _('Description:'), f.text_area(:description, :rows => 10) ) %> | 6 | <%= display_form_field( _('Description:'), f.text_area(:description, :rows => 10) ) %> |
7 | <% f.fields_for :image_builder, @product.image do |i| %> | 7 | <% f.fields_for :image_builder, @product.image do |i| %> |
app/views/memberships/new_community.rhtml
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | 6 | ||
7 | <% labelled_form_for :community, @community do |f| %> | 7 | <% labelled_form_for :community, @community do |f| %> |
8 | 8 | ||
9 | - <%= f.text_field :name, :style => 'width: 100%' %> | 9 | + <%= required f.text_field(:name, :style => 'width: 100%') %> |
10 | 10 | ||
11 | <%= f.text_area :description, :style => 'width: 100%; height: 150px;' %> | 11 | <%= f.text_area :description, :style => 'width: 100%; height: 150px;' %> |
12 | 12 |
app/views/role/_form.rhtml
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | <% labelled_form_for :role, role, :url => (mode == :edit) ? {:action => 'update', :id => role} : {:action => 'create'} do |f| %> | 3 | <% labelled_form_for :role, role, :url => (mode == :edit) ? {:action => 'update', :id => role} : {:action => 'create'} do |f| %> |
4 | 4 | ||
5 | - <%= f.text_field :name %> | 5 | + <%= required f.text_field(:name) %> |
6 | 6 | ||
7 | <%= _('Permissions:') %> <br> | 7 | <%= _('Permissions:') %> <br> |
8 | <% permissions.keys.each do |p| %> | 8 | <% permissions.keys.each do |p| %> |
public/stylesheets/forms.css
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class FormsHelperTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + include FormsHelper | ||
6 | + include ActionView::Helpers::TagHelper | ||
7 | + | ||
8 | + should 'wrapper required fields in <span class=required-field>' do | ||
9 | + content = required('<input type=text name=test>') | ||
10 | + assert_tag_in_string content, :tag => 'span', :attributes => {:class => 'required-field'} | ||
11 | + end | ||
12 | + | ||
13 | +end |