_form.html.erb如何爲jQuery.validator添加自定義消息?
<div class="form-group grading_weighments_div">
<%= f.fields_for :grading_weighments do |gw| %>
<div class="grading_weighments_wrapper">
<div class="form-group weights_div">
<%= gw.label :weights ,class:"sr-only"%>
<%= gw.text_field :weights ,placeholder:"Weight", class:"form-control weights", autocomplete:"off" ,autofocus:true%>
</div>
<div class="form-group boxes_div">
<%= gw.label :box_count ,class:"sr-only"%>
<%= gw.text_field :box_count, placeholder:"Boxes", class:"form-control boxes", autocomplete:"off" %>
</div>
<div class="form-group remove_icon_div">
<%= gw.link_to_remove class:'btn btn-danger', title:"Remove this weight", data: { toggle: "tooltip", placement:"bottom" } do%>
<i class="fa fa-minus"></i>
<%end%>
</div>
</div>
<%end%>
<%= f.link_to_add :grading_weighments ,style:'display:none', class:'btn btn-primary add_grading_weighments' , title:"Add Gradings", data: { toggle: "tooltip", placement:"right" } do%>
<i class="fa fa-plus"></i>
<%end%>
</div>
驗證
jQuery.validator.addClassRules({
weights:{
required:true,
number:true,
min:1,
},
boxes:{
required:true,
digits:true,
min:1
}
});
在這裏,我想爲以上字段添加自定義消息。我在這裏使用jQuery.validator.addClassRules
。這怎麼可能。這裏我加了message:{}
。但不行。
您是否試過閱讀文檔? http://jqueryvalidation.org/documentation/ –