summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-11-12 19:16:19 +0100
committerAzul <azul@leap.se>2012-11-12 19:16:19 +0100
commit05ea71016fd54a14159c72299c25efbdc2f177bc (patch)
tree00fe65cfe0f5d7e09778cf7e6bef304dd16f35c9
parent67dc2685a72c125b53f351c3a75bf812123e96bd (diff)
adding client side validations to the mix
-rw-r--r--Gemfile.lock6
-rw-r--r--app/assets/javascripts/application.js2
-rw-r--r--config/initializers/client_side_validations.rb14
-rw-r--r--ui_dependencies.rb2
-rw-r--r--users/app/views/users/new.html.haml2
5 files changed, 25 insertions, 1 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 6792476..a7d110d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -61,6 +61,10 @@ GEM
arel (3.0.2)
bootstrap-sass (2.1.0.0)
builder (3.0.3)
+ client_side_validations (3.2.1)
+ client_side_validations-simple_form (2.0.0)
+ client_side_validations (~> 3.2.0)
+ simple_form (~> 2.0.3)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -173,6 +177,8 @@ PLATFORMS
DEPENDENCIES
bootstrap-sass (~> 2.1.0)
+ client_side_validations
+ client_side_validations-simple_form
coffee-rails (~> 3.2.2)
haml (~> 3.1.7)
haml-rails (~> 0.3.4)
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index dc975d4..f7ca1ec 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -16,3 +16,5 @@
//= require users
//= require_tree .
//= require bootstrap
+//= require rails.validations
+//= require rails.validations.simple_form
diff --git a/config/initializers/client_side_validations.rb b/config/initializers/client_side_validations.rb
new file mode 100644
index 0000000..2c73fa3
--- /dev/null
+++ b/config/initializers/client_side_validations.rb
@@ -0,0 +1,14 @@
+# ClientSideValidations Initializer
+
+# Uncomment to disable uniqueness validator, possible security issue
+# ClientSideValidations::Config.disabled_validators = [:uniqueness]
+
+# Uncomment the following block if you want each input field to have the validation messages attached.
+ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
+ unless html_tag =~ /^<label/
+ %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
+ else
+ %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
+ end
+end
+
diff --git a/ui_dependencies.rb b/ui_dependencies.rb
index 9b9f853..44f8f32 100644
--- a/ui_dependencies.rb
+++ b/ui_dependencies.rb
@@ -2,6 +2,8 @@ gem "haml", "~> 3.1.7"
gem "bootstrap-sass", "~> 2.1.0"
gem "jquery-rails"
gem "simple_form"
+gem 'client_side_validations'
+gem 'client_side_validations-simple_form'
group :assets do
gem "haml-rails", "~> 0.3.4"
diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml
index 835e99a..3e7d06d 100644
--- a/users/app/views/users/new.html.haml
+++ b/users/app/views/users/new.html.haml
@@ -1,6 +1,6 @@
.span8.offset2
%h2=t :signup
- = simple_form_for @user, :html => {:class => 'form-horizontal'} do |f|
+ = simple_form_for @user, :validate => true, :html => {:class => 'form-horizontal'} do |f|
%legend=t :signup_message
= f.input :login, :input_html => { :id => :srp_username }
= f.input :password, :required => true, :input_html => { :id => :srp_password }