On Thursday 24 November 2011 15:52:00 ifarkas(a)redhat.com wrote:
From: Imre Farkas <ifarkas(a)redhat.com>
---
src/app/helpers/application_helper.rb | 18 ++++++++++++++++++
src/app/views/users/_form.html.haml | 8 ++++----
src/app/views/users/edit.html.haml | 2 +-
src/app/views/users/new.html.haml | 2 +-
4 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/src/app/helpers/application_helper.rb
b/src/app/helpers/application_helper.rb index cbb7a43..2c6aa05 100644
--- a/src/app/helpers/application_helper.rb
+++ b/src/app/helpers/application_helper.rb
@@ -161,4 +161,22 @@ module ApplicationHelper
end
module_function :count_uptime
+
+ class FormBuilderWithRequiredFields < ActionView::Helpers::FormBuilder
+
+ def label(method, text = nil, options = {}, &block)
+ text << ' *' if required?(object, method, options)
+ super(method, text, options, &block)
+ end
+
+ private
+
+ def required?(object, attribute, options)
+ return options[:required] if options.has_key?(:required)
+ object.class.validators_on(attribute).map(&:class).include?
ActiveModel::Validations::PresenceValidator + end
+
+ end
+
end
+
pls remove this new line on EOF ^^
diff --git a/src/app/views/users/_form.html.haml
b/src/app/views/users/_form.html.haml index 665a35c..e3b8945 100644
--- a/src/app/views/users/_form.html.haml
+++ b/src/app/views/users/_form.html.haml
@@ -9,17 +9,17 @@
= form.label :last_name, t(:last_name)
= form.text_field :last_name, :class =>"check_change"
%p
- = form.label :email, t(:email)
+ = form.label :email, t(:email), :required => true
= form.text_field :email, :class =>"check_change"
%fieldset
%p
- = form.label :login, t(:choose_name)
+ = form.label :login, t(:choose_name), :required => true
= form.text_field :login, :class => "em check_change"
%p
- = form.label :password, form.object.new_record? ? t(:choose_password) :
t(:change_password) + = form.label :password, form.object.new_record? ?
t(:choose_password) : t(:change_password), :required =>
form.object.new_record? = form.password_field :password
%p
- = form.label :password_confirmation, t(:confirm_password)
+ = form.label :password_confirmation, t(:confirm_password), :required =>
form.object.new_record? = form.password_field :password_confirmation
-if check_privilege(Privilege::MODIFY, User)
diff --git a/src/app/views/users/edit.html.haml
b/src/app/views/users/edit.html.haml index 70bf0c4..81e42db 100644
--- a/src/app/views/users/edit.html.haml
+++ b/src/app/views/users/edit.html.haml
@@ -21,5 +21,5 @@
%dd#email= @user.email
%dt=t'users.show.username'
%dd#login= @user.login
- = form_for @user, :url => user_path(@user), :html => { :method => :put,
:class => 'generic' } do |f| + = form_for @user, :url =>
user_path(@user), :builder =>
ApplicationHelper::FormBuilderWithRequiredFields, :html => { :method =>
:put, :class => 'generic' } do |f| = render :partial => "form",
:locals =>
{ :form => f, :cancel_path => users_path } diff --git
a/src/app/views/users/new.html.haml b/src/app/views/users/new.html.haml
index e6e914d..b612564 100644
--- a/src/app/views/users/new.html.haml
+++ b/src/app/views/users/new.html.haml
@@ -23,7 +23,7 @@
%dd#email
%dt=t'users.show.username'
%dd#login
- = form_for @user, :url => users_path, :html => {:class =>
'generic'} do
|f| + = form_for @user, :url => users_path, :builder =>
ApplicationHelper::FormBuilderWithRequiredFields, :html => {:class =>
'generic'} do |f| -if current_user
= render :partial => "form", :locals => { :form => f }
-else
One small inline note, it works fine, so ACK.