How do jquery live validate on dynamic fileld in rails

370 Views Asked by At

I give same class name for dynamic and static field.its not working and i got this error

Uncaught Error: LiveValidation::initialize - No element with reference or id of 'parent_first_name' exists!

how can fixed it.I have try to override id name for dynamic field & static field.Id override only static field but not override for dynamic field. How do live validate dynamic field? please help me

Here my validation.js file.Bellow i mentioned one field only

  if($(".parent_first_name").length > 0) {
     var myparent_first_name = new LiveValidation('parent_first_name', { onlyOnBlur: true });
     myparent_first_name.add( Validate.Presence );

   }

Here my form.html.erb file.Bellow i mentioned one field only

  <div class="field">
    <%= p.label :first_name %><br>
    <%= p.text_field :first_name , :class => "parent_first_name" %>
  </div>

Thanks!

1

There are 1 best solutions below

1
On

Try it,

<div class="field">
    <%= p.label :first_name %><br>
    <%= p.text_field(:first_name , :class => "parent_first_name") %>
  </div>`

just added the Parentheses