I have some nested attributes (using simple_fields_for) in a simple_form in rails.
The main form starts like this, and parsley is working fine:
<%= simple_form_for(@enquiry, wrapper: :vertical_form, html: {"data-parsley-validate" => ''}) do |f| %>
<%= f.input :total_budget, class: 'form-control', placeholder: 'Please enter your total or per head budget', label: 'Budget', input_html: { "data-parsley-error-message" => "Please enter a budget", "data-parsley-trigger" => "focusin focusout change" } %>
However, in the form further down I have this:
<%= f.simple_fields_for :client do |builder| %>
<%= render 'sign_up_fields', f: builder %>
<% end %>
and the rendered partial is this:
<div class="row">
<div class="col-md-6">
<div class="form-group">
<%= f.input :first_name, class: 'form-control', placeholder: 'First name' %>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<%= f.input :last_name, class: 'form-control', placeholder: 'Last name' %>
</div>
</div>
</div>
<%= f.simple_fields_for :user do |builder| %>
<div class='row'>
<div class="col-md-6">
<div class="form-group">
<%= builder.input :email, class: 'form-control', placeholder: 'Email', required: "true" %>
</div>
<% if builder.object.errors[:email] %>
<%= f.object.errors[:email].join(", ") %>
<% end %>
</div>
<div class="col-md-6">
<div class="form-group">
<%= f.input :phone_number, class: 'form-control', placeholder: 'Phone number' %>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<%= builder.input :password, class: 'form-control', placeholder: 'Password', required: "true" %>
</div>
<% if builder.object.errors[:password] %>
<%= f.object.errors[:password].join(", ") %>
<% end %>
</div>
<% end %>
</div>
I have tried adding the parsley-data-validation to the simple_fields_for parts in various ways, tried it without, and tried adding parsley validations to the actual fields but that hasn't worked either.
Is there something else I should be doing differently?
Cheers
I had the wrong ID for the field I was validating. I still had to use extra js to validate the field; it wasn't picked up by the main HTML: {"data-parsley-validate" => ''}
in the top of the form.
$('#enquiry_client_attributes_user_attributes_email').parsley('validate');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.