我在 rails 3 中使用 nested_form 并且我有一个用户可以添加或删除的动态字段。
我需要知道这些字段的 jquery 选择器,以便我可以在字段之间进行一些 javascript 计算,目前动态字段将当前日期时间设置为字段,人们通常如何处理动态字段验证?
<%= nested_form_for [@project, @quote], :html => {:class =>'form-inline'} do |f| %>
<div>
<%= f.hidden_field :project_id %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :status %>
<%= f.text_field :status %>
</div>
<p>
<h4> Labour Items </h4>
</p>
<p>
<%= f.fields_for :labouritems, :html => { :class => 'form-vertical' } do |builder| %>
<%= builder.label :description %>
<%= builder.text_field :description, :class => "input-medium" %>
<%= builder.label :hours %>
<%= builder.text_field :hours, :class => "input-mini" %>
<%= builder.label :total %>
<%= builder.text_field :total, :class => "input-mini" %>
<%= builder.label "Mup/Hr" %>
<%= builder.text_field :muphourrate, :class => "input-mini" %>
<%= builder.label "Mup/Total" %>
<%= builder.text_field :muptotal, :class => "input-mini" %>
<%= builder.label "Mup/%" %>
<%= builder.text_field :muppercent, :class => "input-mini" %>
<%= builder.label "Contractor" %>
<%= builder.autocomplete_field :contractor_name, autocomplete_contractor_firstname_contractors_path, :update_elements => {:id => "##{form_tag_id(builder.object_name, :contractor_id)}" , :hourly_rate => "##{form_tag_id(builder.object_name, :contractor_rate)}" },:class => "input-small",:placeholder => "Seach" %>
<%= builder.hidden_field :contractor_id %>
<%= builder.label "Rate/hr" %>
<%= builder.text_field :contractor_rate,:class => "input-mini" %>
<%= builder.label "Work %" %>
<%= builder.text_field :progress_percent, :class => "input-mini" %>
<%= builder.label "Work $" %>
<%= builder.text_field :progress_payment, :class => "input-mini" %>
<%= builder.link_to_remove "Delete",:class => 'btn btn-small btn-danger' %>
<% end %>
<%= f.link_to_add "Add Item", :labouritems, :class => 'btn btn-small btn-primary' %>
</p>