Commit 2ac0268015376b77106223227de4de52d9012886

Authored by Joenio Costa
1 parent c091bfbf

ActionItem182: messages for mandatory fields

app/helpers/forms_helper.rb
@@ -100,6 +100,13 @@ module FormsHelper @@ -100,6 +100,13 @@ module FormsHelper
100 content_tag('span', content, :class => 'required-field') 100 content_tag('span', content, :class => 'required-field')
101 end 101 end
102 102
  103 + def required_fields_message
  104 + content_tag('p', content_tag('span',
  105 + _("The <label class='pseudoformlabel'>highlighted</label> fields are mandatory."),
  106 + :class => 'required-field'
  107 + ))
  108 + end
  109 +
103 protected 110 protected
104 def self.next_id_number 111 def self.next_id_number
105 if defined? @@id_num 112 if defined? @@id_num
app/views/account/_signup_form.rhtml
1 <%= error_messages_for :user %> 1 <%= error_messages_for :user %>
  2 +
2 <% labelled_form_for :user, @user, 3 <% labelled_form_for :user, @user,
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 :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| -%> 5 } do |f| -%>
5 6
  7 +<%= required_fields_message %>
  8 +
6 <%= required f.text_field(:login, 9 <%= required f.text_field(:login,
7 :onchange => 'this.value = convToValidLogin( this.value )') %> 10 :onchange => 'this.value = convToValidLogin( this.value )') %>
8 <small><%= help %></small> 11 <small><%= help %></small>
app/views/categories/_form.rhtml
1 <%= error_messages_for 'category' %> 1 <%= error_messages_for 'category' %>
2 2
3 <% labelled_form_for 'category', @category, :html => { :multipart => true} do |f| %> 3 <% labelled_form_for 'category', @category, :html => { :multipart => true} do |f| %>
  4 +
  5 + <%= required_fields_message %>
  6 +
4 <% if @category.new_record? %> 7 <% if @category.new_record? %>
5 <% if @category.parent %> 8 <% if @category.parent %>
6 <%= hidden_field_tag('parent_id', @category.parent.id) %> 9 <%= hidden_field_tag('parent_id', @category.parent.id) %>
app/views/cms/_event.rhtml
  1 +<%= required_fields_message %>
  2 +
1 <%# TODO add Textile help here %> 3 <%# TODO add Textile help here %>
2 <%= render :file => 'shared/tiny_mce' %> 4 <%= render :file => 'shared/tiny_mce' %>
3 5
app/views/cms/_folder.rhtml
  1 +<%= required_fields_message %>
1 2
2 <%# TODO add Textile help here %> 3 <%# TODO add Textile help here %>
3 <%= render :file => 'shared/tiny_mce' %> 4 <%= render :file => 'shared/tiny_mce' %>
app/views/cms/_rss_feed.rhtml
  1 +<%= required_fields_message %>
  2 +
1 <%= required f.text_field(:name) %> 3 <%= required f.text_field(:name) %>
2 4
3 <%= required labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> 5 <%= required labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %>
app/views/cms/_textile_article.rhtml
  1 +<%= required_fields_message %>
1 2
2 <%# TODO add Textile help here %> 3 <%# TODO add Textile help here %>
3 4
app/views/cms/_tiny_mce_article.rhtml
  1 +<%= required_fields_message %>
1 2
2 <%= render :file => 'shared/tiny_mce' %> 3 <%= render :file => 'shared/tiny_mce' %>
3 4
app/views/cms/_uploaded_file.rhtml
  1 +<%= required_fields_message %>
  2 +
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)) %> 3 <%= 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 4
3 <%= labelled_form_field(_('Describe this file:'), text_area(:article, :abstract)) %> 5 <%= labelled_form_field(_('Describe this file:'), text_area(:article, :abstract)) %>
app/views/contact/new.rhtml
@@ -2,8 +2,11 @@ @@ -2,8 +2,11 @@
2 2
3 <%= error_messages_for 'contact' %> 3 <%= error_messages_for 'contact' %>
4 4
  5 +
5 <% labelled_form_for :contact, @contact do |f| %> 6 <% labelled_form_for :contact, @contact do |f| %>
6 7
  8 + <%= required_fields_message %>
  9 +
7 <%= f.text_field :name %> 10 <%= f.text_field :name %>
8 <%= f.text_field :email %> 11 <%= f.text_field :email %>
9 <%= labelled_form_field _('City and state'), select_city(true) %> 12 <%= labelled_form_field _('City and state'), select_city(true) %>
app/views/content_viewer/_comment_form.rhtml
@@ -19,6 +19,8 @@ @@ -19,6 +19,8 @@
19 19
20 <% form_tag( @page.url, { :id => comment_form_id } ) do %> 20 <% form_tag( @page.url, { :id => comment_form_id } ) do %>
21 21
  22 + <%= required_fields_message %>
  23 +
22 <% unless logged_in? %> 24 <% unless logged_in? %>
23 25
24 <%= required labelled_form_field(_('Name'), text_field(:comment, :name)) %> 26 <%= required labelled_form_field(_('Name'), text_field(:comment, :name)) %>
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 + <%= required_fields_message %>
  5 +
4 <%= required display_form_field( _('Name:'), f.text_field(:name) ) %> 6 <%= required display_form_field( _('Name:'), f.text_field(:name) ) %>
5 <%= display_form_field( _('Price:'), f.text_field(:price) ) %> 7 <%= display_form_field( _('Price:'), f.text_field(:price) ) %>
6 <%= display_form_field( _('Description:'), f.text_area(:description, :rows => 10) ) %> 8 <%= display_form_field( _('Description:'), f.text_area(:description, :rows => 10) ) %>
app/views/memberships/new_community.rhtml
@@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
6 6
7 <% labelled_form_for :community, @community do |f| %> 7 <% labelled_form_for :community, @community do |f| %>
8 8
  9 + <%= required_fields_message %>
  10 +
9 <%= required f.text_field(:name, :style => 'width: 100%') %> 11 <%= required f.text_field(:name, :style => 'width: 100%') %>
10 12
11 <%= f.text_area :description, :style => 'width: 100%; height: 150px;' %> 13 <%= f.text_area :description, :style => 'width: 100%; height: 150px;' %>
app/views/role/_form.rhtml
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
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 + <%= required_fields_message %>
  6 +
5 <%= required f.text_field(:name) %> 7 <%= required f.text_field(:name) %>
6 8
7 <%= _('Permissions:') %> <br> 9 <%= _('Permissions:') %> <br>
public/stylesheets/forms.css
@@ -3,9 +3,12 @@ @@ -3,9 +3,12 @@
3 padding: 3px 0px; 3 padding: 3px 0px;
4 } 4 }
5 5
  6 +.pseudoformlabel,
6 .formlabel { 7 .formlabel {
7 - /* font-size: 11px; */  
8 color: #444; 8 color: #444;
  9 +}
  10 +.formlabel {
  11 + /* font-size: 11px; */
9 display: block; 12 display: block;
10 padding: 2px 5px; 13 padding: 2px 5px;
11 } 14 }
test/unit/forms_helper_test.rb
@@ -10,4 +10,20 @@ class FormsHelperTest &lt; Test::Unit::TestCase @@ -10,4 +10,20 @@ class FormsHelperTest &lt; Test::Unit::TestCase
10 assert_tag_in_string content, :tag => 'span', :attributes => {:class => 'required-field'} 10 assert_tag_in_string content, :tag => 'span', :attributes => {:class => 'required-field'}
11 end 11 end
12 12
  13 + should 'wrapper required fields message in <span class=required-field>' do
  14 + content = required_fields_message()
  15 + assert_tag_in_string content, :tag => 'span', :attributes => {:class => 'required-field'}
  16 + end
  17 +
  18 + should 'wrapper highlighted in label pseudoformlabel' do
  19 + content = required_fields_message()
  20 + assert_tag_in_string content, :tag => 'label', :content => 'highlighted', :attributes => {:class => 'pseudoformlabel'}
  21 + end
  22 +
  23 + protected
  24 +
  25 + def _(text)
  26 + text
  27 + end
  28 +
13 end 29 end