Skip to content

Commit

Permalink
global disabling of livevalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
porras committed Nov 19, 2007
1 parent 6a839c0 commit 511585d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README
Expand Up @@ -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>)
Expand Down
3 changes: 3 additions & 0 deletions lib/live_validations.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/form_helpers_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 511585d

Please sign in to comment.