diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index 0068ac0..a5d959d 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -96,6 +96,10 @@ module FormsHelper 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 = ''", :with => 'state_id') end + def required(content) + content_tag('span', content, :class => 'required-field') + end + protected def self.next_id_number if defined? @@id_num diff --git a/app/views/account/_signup_form.rhtml b/app/views/account/_signup_form.rhtml index 3c7c381..456ef99 100644 --- a/app/views/account/_signup_form.rhtml +++ b/app/views/account/_signup_form.rhtml @@ -3,20 +3,20 @@ :html => { :help=>_('Fill all this fields to join in this environment.
If you forgot your password, do not create a new account, click on the "I forgot my password!" link. ;-)'), :id => 'profile-data' } do |f| -%> -<%= f.text_field :login, - :onchange => 'this.value = convToValidLogin( this.value )' %> +<%= required f.text_field(:login, + :onchange => 'this.value = convToValidLogin( this.value )') %> <%= help %> -<%= f.text_field :email, - :help => help=_('We\'ll send you an e-mail to validate your registration.') %> +<%= required f.text_field(:email, + :help => help=_('We\'ll send you an e-mail to validate your registration.')) %> <%= help %> -<%= f.password_field :password, - :help => help=_('Choose a password that you can remember easily.') %> +<%= required f.password_field(:password, + :help => help=_('Choose a password that you can remember easily.')) %> <%= help %> -<%= f.password_field :password_confirmation, - :help => help=_('To confirm, repeat your password.') %> +<%= required f.password_field(:password_confirmation, + :help => help=_('To confirm, repeat your password.')) %> <%= help %> <%= icaptcha_field() %> diff --git a/app/views/categories/_form.rhtml b/app/views/categories/_form.rhtml index 5be6ceb..e4110c8 100644 --- a/app/views/categories/_form.rhtml +++ b/app/views/categories/_form.rhtml @@ -12,7 +12,7 @@ <%= select_color_for_category %> - <%= f.text_field 'name' %> + <%= required f.text_field('name') %> <% f.fields_for :image_builder, @category.image do |i| %> <%= file_field_or_thumbnail(_('Image:'), @category.image, i) %> diff --git a/app/views/cms/_event.rhtml b/app/views/cms/_event.rhtml index 59e00e0..26b3ae2 100644 --- a/app/views/cms/_event.rhtml +++ b/app/views/cms/_event.rhtml @@ -1,7 +1,7 @@ <%# TODO add Textile help here %> <%= render :file => 'shared/tiny_mce' %> -<%= f.text_field('name', :size => '64') %> +<%= required f.text_field('name', :size => '64') %> <%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> diff --git a/app/views/cms/_folder.rhtml b/app/views/cms/_folder.rhtml index 89b274d..82bc1d9 100644 --- a/app/views/cms/_folder.rhtml +++ b/app/views/cms/_folder.rhtml @@ -2,6 +2,6 @@ <%# TODO add Textile help here %> <%= render :file => 'shared/tiny_mce' %> -<%= f.text_field('name', :size => '64') %> +<%= required f.text_field('name', :size => '64') %> <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64)) %> diff --git a/app/views/cms/_rss_feed.rhtml b/app/views/cms/_rss_feed.rhtml index 9886e4a..bdb7331 100644 --- a/app/views/cms/_rss_feed.rhtml +++ b/app/views/cms/_rss_feed.rhtml @@ -1,6 +1,6 @@ -<%= f.text_field :name %> +<%= required f.text_field(:name) %> -<%= labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> +<%= required labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> <%= labelled_form_field(_('Use as item description:'), select(:article, :feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %> diff --git a/app/views/cms/_textile_article.rhtml b/app/views/cms/_textile_article.rhtml index a868506..042595c 100644 --- a/app/views/cms/_textile_article.rhtml +++ b/app/views/cms/_textile_article.rhtml @@ -1,7 +1,7 @@ <%# TODO add Textile help here %> -<%= f.text_field('name', :size => '64') %> +<%= required f.text_field('name', :size => '64') %> <%= f.text_area('body', :cols => 64) %> diff --git a/app/views/cms/_tiny_mce_article.rhtml b/app/views/cms/_tiny_mce_article.rhtml index f21db68..0facfd7 100644 --- a/app/views/cms/_tiny_mce_article.rhtml +++ b/app/views/cms/_tiny_mce_article.rhtml @@ -1,7 +1,7 @@ <%= render :file => 'shared/tiny_mce' %> -<%= f.text_field('name', :size => '64') %> +<%= required f.text_field('name', :size => '64') %> <%= f.text_area('body', :cols => 40, :style => 'width:99%') %> diff --git a/app/views/cms/_uploaded_file.rhtml b/app/views/cms/_uploaded_file.rhtml index cf55592..a6a009f 100644 --- a/app/views/cms/_uploaded_file.rhtml +++ b/app/views/cms/_uploaded_file.rhtml @@ -1,3 +1,3 @@ -<%= labelled_form_field(_("Select the file you want to upload (max size %s).") % UploadedFile.max_size.to_humanreadable, file_field(:article, :uploaded_data)) %> +<%= required labelled_form_field(_("Select the file you want to upload (max size %s).") % UploadedFile.max_size.to_humanreadable, file_field(:article, :uploaded_data)) %> <%= labelled_form_field(_('Describe this file:'), text_area(:article, :abstract)) %> diff --git a/app/views/contact/new.rhtml b/app/views/contact/new.rhtml index a91108a..9f37b7e 100644 --- a/app/views/contact/new.rhtml +++ b/app/views/contact/new.rhtml @@ -6,11 +6,11 @@ <%= hidden_field_tag 'contact[target_id]', profile.id %> <%= hidden_field_tag 'contact[requestor_id]', (logged_in? ? current_user.person.id : nil) %> - <%= f.text_field :subject %> - <%= f.text_field :email %> + <%= required f.text_field(:subject) %> + <%= required f.text_field(:email) %> <%= f.text_field :city_and_state %> <%= f.text_field :phone %> - <%= f.text_area :message, :rows => 5 %> + <%= required f.text_area(:message, :rows => 5) %> <%= submit_button(:send, _('Send')) %> diff --git a/app/views/content_viewer/_comment_form.rhtml b/app/views/content_viewer/_comment_form.rhtml index 2267ba8..f7063cd 100644 --- a/app/views/content_viewer/_comment_form.rhtml +++ b/app/views/content_viewer/_comment_form.rhtml @@ -21,8 +21,8 @@ <% unless logged_in? %> - <%= labelled_form_field(_('Name'), text_field(:comment, :name)) %> - <%= labelled_form_field(_('e-mail'), text_field(:comment, :email)) %> + <%= required labelled_form_field(_('Name'), text_field(:comment, :name)) %> + <%= required labelled_form_field(_('e-mail'), text_field(:comment, :email)) %> <%= icaptcha_field() %>
@@ -31,8 +31,8 @@
<% end %>
- <%= labelled_form_field(_('Title'), text_field(:comment, :title)) %>
- <%= labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %>
+ <%= required labelled_form_field(_('Title'), text_field(:comment, :title)) %>
+ <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %>
<% button_bar do %>
<%= submit_button('add', _('Post comment')) %>
<% end %>
diff --git a/app/views/manage_products/_form.rhtml b/app/views/manage_products/_form.rhtml
index 65a9903..0e00208 100644
--- a/app/views/manage_products/_form.rhtml
+++ b/app/views/manage_products/_form.rhtml
@@ -1,7 +1,7 @@
<%= error_messages_for :product %>
<% form_for :product, @product, :html => {:multipart => true }, :url => {:action => mode} do |f| %>
- <%= display_form_field( _('Name:'), f.text_field(:name) ) %>
+ <%= required display_form_field( _('Name:'), f.text_field(:name) ) %>
<%= display_form_field( _('Price:'), f.text_field(:price) ) %>
<%= display_form_field( _('Description:'), f.text_area(:description, :rows => 10) ) %>
<% f.fields_for :image_builder, @product.image do |i| %>
diff --git a/app/views/memberships/new_community.rhtml b/app/views/memberships/new_community.rhtml
index 2b7d6bc..75c488a 100644
--- a/app/views/memberships/new_community.rhtml
+++ b/app/views/memberships/new_community.rhtml
@@ -6,7 +6,7 @@
<% labelled_form_for :community, @community do |f| %>
- <%= f.text_field :name, :style => 'width: 100%' %>
+ <%= required f.text_field(:name, :style => 'width: 100%') %>
<%= f.text_area :description, :style => 'width: 100%; height: 150px;' %>
diff --git a/app/views/role/_form.rhtml b/app/views/role/_form.rhtml
index fc56669..e0fc341 100644
--- a/app/views/role/_form.rhtml
+++ b/app/views/role/_form.rhtml
@@ -2,7 +2,7 @@
<% labelled_form_for :role, role, :url => (mode == :edit) ? {:action => 'update', :id => role} : {:action => 'create'} do |f| %>
- <%= f.text_field :name %>
+ <%= required f.text_field(:name) %>
<%= _('Permissions:') %>
<% permissions.keys.each do |p| %>
diff --git a/public/stylesheets/forms.css b/public/stylesheets/forms.css
index 1c896d5..5bd3121 100644
--- a/public/stylesheets/forms.css
+++ b/public/stylesheets/forms.css
@@ -71,3 +71,12 @@
margin-left: 10px;
}
+/*** REQUIRED FIELDS ***/
+
+#content form .required-field label {
+ font-weight: bold;
+}
+
+#content form .required-field label:after {
+ content: ' (*)';
+}
diff --git a/test/unit/forms_helper_test.rb b/test/unit/forms_helper_test.rb
new file mode 100644
index 0000000..b973744
--- /dev/null
+++ b/test/unit/forms_helper_test.rb
@@ -0,0 +1,13 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class FormsHelperTest < Test::Unit::TestCase
+
+ include FormsHelper
+ include ActionView::Helpers::TagHelper
+
+ should 'wrapper required fields in ' do
+ content = required('')
+ assert_tag_in_string content, :tag => 'span', :attributes => {:class => 'required-field'}
+ end
+
+end
--
libgit2 0.21.2