Skip to content
Browse files

global disabling of livevalidation

  • Loading branch information...
1 parent 6a839c0 commit 511585d7bbfbb9f0425348558213f08b042d7655 @porras porras committed Nov 19, 2007
Showing with 19 additions and 0 deletions.
  1. +8 −0 README
  2. +3 −0 lib/live_validations.rb
  3. +8 −0 test/form_helpers_test.rb
View
8 README
@@ -26,6 +26,14 @@ This plugin generates the needed Javascript code to run client-side the validati
[etc ...]
<% end %>
+You can disable live validation using '':live => false'', either for a given field:
+
+ <%= f.text_field :name, :live => false %>
+
+or for a whole validation:
+
+ validates_presence_of :name, :live => false
+
== TODO
* Support some lacking validations and options (mainly, <tt>validates_confirmation_of</tt>)
View
3 lib/live_validations.rb
@@ -41,6 +41,9 @@ def define_validations(validation_type, attr_names)
end
def add_live_validation(attr_name, type, configuration = {})
+ live = configuration.delete(:live)
+ live = true if live.nil?
+ return unless live
@live_validations ||= {}
@live_validations[attr_name] ||= {}
@live_validations[attr_name][type] = configuration
View
8 test/form_helpers_test.rb
@@ -73,6 +73,14 @@ def test_without_live
check_form_item :type => 'text', :name => 'name'
end
+ def test_without_live_global
+ Resource.class_eval do
+ validates_presence_of :name, :live => false
+ end
+ get :name
+ check_form_item :type => 'text', :name => 'name'
+ end
+
def test_with_string
Resource.class_eval do
validates_presence_of :name

0 comments on commit 511585d

Please sign in to comment.
Something went wrong with that request. Please try again.