summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/initializers/client_side_validations.rb2
-rw-r--r--users/app/assets/javascripts/users.js.coffee2
-rw-r--r--users/app/models/user.rb8
-rw-r--r--users/app/views/users/_form.html.haml2
4 files changed, 10 insertions, 4 deletions
diff --git a/config/initializers/client_side_validations.rb b/config/initializers/client_side_validations.rb
index 2c73fa3..252aded 100644
--- a/config/initializers/client_side_validations.rb
+++ b/config/initializers/client_side_validations.rb
@@ -1,7 +1,7 @@
# ClientSideValidations Initializer
# Uncomment to disable uniqueness validator, possible security issue
-# ClientSideValidations::Config.disabled_validators = [:uniqueness]
+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|
diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee
index 5663161..f0bb3dd 100644
--- a/users/app/assets/javascripts/users.js.coffee
+++ b/users/app/assets/javascripts/users.js.coffee
@@ -15,7 +15,7 @@ srp.updated = ->
srp.error = (message) ->
if $.isPlainObject(message) && message.errors
for field, error of message.errors
- element = $('form input[name="session['+field+']"]')
+ element = $('form input[name$="['+field+']"]')
next unless element
element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false)
else
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 624754b..39d079a 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -9,7 +9,8 @@ class User < CouchRest::Model::Base
:presence => true
validates :login,
- :uniqueness => true
+ :uniqueness => true,
+ :if => :serverside?
validates :login,
:format => { :with => /\A[A-Za-z\d_]+\z/,
@@ -74,4 +75,9 @@ class User < CouchRest::Model::Base
def password
password_verifier
end
+
+ # used as a condition for validations that are server side only
+ def serverside?
+ true
+ end
end
diff --git a/users/app/views/users/_form.html.haml b/users/app/views/users/_form.html.haml
index d26d17d..fc835af 100644
--- a/users/app/views/users/_form.html.haml
+++ b/users/app/views/users/_form.html.haml
@@ -1,5 +1,5 @@
- html = {:class => 'form-horizontal user form ' + (@user.new_record? ? 'new' : 'edit')}
-= simple_form_for @user, :validate => true, :html => html do |f|
+= simple_form_for @user, :validate => true, :format => :json, :html => html do |f|
%legend
= @user.new_record? ? t(:signup_message) : t(:edit_settings)
= f.input :login, :input_html => { :id => :srp_username }