rails.validations.js throwing an error
Hi,
after including your gem I receive an error in my javascript console when trying to invoke a field validation by moving out of an input field:
TypeError: Result of expression 'clientSideValidations.formBuilders[settings.type]' [undefined] is not an object.
rails.validations.js:63
and no error is displayed inside my form underneath the input field.
My setup:
rails 3.0.9 simple_form: 1.4.2 client_side_validations 3.1.0
Can you please gist the resulting HTML?
https://gist.github.com/1055865
the validation should take place for line 36
Are you sure you're using NestedForm? The 'type' on the settings variable says 'NestedForm'. Can you possibly gist template you're using to render the form?
I'm getting the same error, though I'm using Formtastic.
Uncaught TypeError: Cannot call method 'add' of undefined rails.validations.js:63
On line 63, I found settings.type to be "Formtastic::SemanticFormBuilder"
rails: 3.0.7 formtastic: 1.2.4 client_side_validations: 3.0.5
@robhunter can you update to the latest ClientSideValidations and see if the error still exists?
So, I'd changed it to 3.0.5 because this error was coming up:
17:25:02 web.1 | /Users/robhunter/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in const_missing_from_s3_library': uninitialized constant Formtastic::FormBuilder (NameError) 17:25:02 web.1 | from /Users/robhunter/.rvm/gems/ruby-1.9.2-p180/gems/client_side_validations-3.1.0/lib/client_side_validations/formtastic.rb:20:in<top (required)>'
and switched to version 3.0.5 on the advice of this post:
http://stackoverflow.com/questions/6438449/rails-3-uninitialized-constant-formtasticformbuilder-error-after-deploying-a
I'm guessing you tried to install the 3.1 version of ClientSideValidations with Formtastic 1.x
Try this in your Gemfile
gem 'client_side_validations', '~> 3.0.11'
The 3.0.x version uses Formtastic 1.x
On Fri, Jul 15, 2011 at 5:28 PM, robhunter [email protected] wrote:
So, I'd changed it to 3.0.5 because this error was coming up:
17:25:02 web.1 | /Users/robhunter/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in
const_missing_from_s3_library': uninitialized constant Formtastic::FormBuilder (NameError) 17:25:02 web.1 | from /Users/robhunter/.rvm/gems/ruby-1.9.2-p180/gems/client_side_validations-3.1.0/lib/client_side_validations/formtastic.rb:20:in<top (required)>'and switched to version 3.0.5 on the advice of this post:
http://stackoverflow.com/questions/6438449/rails-3-uninitialized-constant-formtasticformbuilder-error-after-deploying-a
Reply to this email directly or view it on GitHub: https://github.com/bcardarella/client_side_validations/issues/121#issuecomment-1582896
I get the same js error with 3.0.12.
I'm going to try updating formtastic and using the latest version of ClientSideValidations.
Is this a particularly common error? Seems like clientSideValidations.formBuilders isn't populating.
I'm not certain. It is very difficult for me to address these issues without examples.
rails: 3.0.9 formtastic: 1.2.4 client_side_validations: 3.0.5
clientSideValidations.formBuilders[settings.type] is undefined Line 63
class SomeClass < ActiveRecord::Base
validates_presence_of :url, :message => "Must have a value"
...
end
clientSideValidations.callbacks.element.fail = function(element, message, callback) {
callback();
if (element.data('valid') !== false) {
element.validationEngine('showPrompt', message, 'error', true)
}
}
clientSideValidations.callbacks.element.pass = function(element, callback) {
element.validationEngine('hidePrompt')
}
<%= semantic_form_for @some_class, :validate => true do |f| %>
<%= f.inputs do %>
<%= f.autocompleted_input :this_class, :url => this_class_autocomplete_path %>
<%= f.input :url %>
<% end %>
<% end %>
Some quick debugging in firebug shows the clientSideValidations.formBuilders object below:
ActionView::Helpers::FormBuilder
Object { add=function(), remove=function()}
Formtastic::FormBuilder
Object { add=function(), remove=function()}
NestedForm::Builder
Object { add=function(), remove=function()}
SimpleForm::FormBuilder
The requested formbuilder from settings.type is "Formtastic::SemanticFormBuilder", so the formbuilder is undefined. Evidently a mismatch between gems?
Looks like this issue has been identified and resolved going one direction
https://github.com/bcardarella/client_side_validations/pull/105/files
For my a working fix I reversed the assignment:
clientSideValidations.formBuilders['Formtastic::SemanticFormBuilder'] = clientSideValidations.formBuilders['Formtastic::FormBuilder']
This error is happening because of a namespace issue change with Formtastic.
In the next release of ClientSideValidations I'm removing Formtastic and extracting it to its own adapter: http://github.com/bcardarella/client_side_validations-formtastic
This issue will be resolved in that gem.