diff --git a/lib/form_helpers.rb b/lib/form_helpers.rb index adbeab2..6629d11 100644 --- a/lib/form_helpers.rb +++ b/lib/form_helpers.rb @@ -17,7 +17,7 @@ def live_validations_for(object_name, method) private def live_validation(object_name, method) - if validations = self.instance_variable_get("@#{object_name.to_s}").class.live_validations[method] rescue false + if validations = self.instance_variable_get("@#{object_name.to_s}").class.live_validations[method.to_sym] rescue false field_name = "#{object_name}_#{method}" initialize_validator(field_name) + validations.map do |type, configuration| diff --git a/test/form_helpers_test.rb b/test/form_helpers_test.rb index 1c24fed..065e6ba 100644 --- a/test/form_helpers_test.rb +++ b/test/form_helpers_test.rb @@ -18,6 +18,11 @@ def without_live render :inline => "<% form_for(:resource, :url => resources_path) do |f| %><%= f.text_field :name, :live => false %><% end %>" end + def with_string + @resource = Resource.new + render :inline => "<% form_for(:resource, :url => resources_path) do |f| %><%= f.text_field 'name' %><% end %>" + end + def name @resource = Resource.new render_form(:text, :name) @@ -68,6 +73,14 @@ def test_without_live check_form_item :type => 'text', :name => 'name' end + def test_with_string + Resource.class_eval do + validates_presence_of :name + end + get :with_string + check_form_item :type => 'text', :name => 'name', :script => "var resource_name = new LiveValidation('resource_name');resource_name.add(Validate.Presence, {validMessage: \"\"})" + end + def test_presence Resource.class_eval do validates_presence_of :name