From 511585d7bbfbb9f0425348558213f08b042d7655 Mon Sep 17 00:00:00 2001 From: Sergio Gil Date: Mon, 19 Nov 2007 14:12:01 +0000 Subject: [PATCH] global disabling of livevalidation --- README | 8 ++++++++ lib/live_validations.rb | 3 +++ test/form_helpers_test.rb | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/README b/README index 22ff611..5e5ce02 100644 --- a/README +++ b/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, validates_confirmation_of) diff --git a/lib/live_validations.rb b/lib/live_validations.rb index a99ed6c..2850d39 100644 --- a/lib/live_validations.rb +++ b/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 diff --git a/test/form_helpers_test.rb b/test/form_helpers_test.rb index 065e6ba..98f3742 100644 --- a/test/form_helpers_test.rb +++ b/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