如何使用bootstrap验证器验证输入标记列表 我正在使用spring,jquery和bootstrap
这是我的HTML:
<form id="myForm" class="form-horizontal" method="post" action="/hello">
<input class="form-control" type="text" name="myobject[0].descripton />
<input class="form-control" type="text" name="myobject[1].descripton />
<input class="form-control" type="text" name="myobject[2].descripton />
<input class="form-control" type="text" name="myobject[3].descripton />
</form>
这是我的验证员:
$('#myForm').bootstrapValidator({
feedbackIcons : {
valid : glyphicon glyphicon-ok,
invalid : glyphicon glyhicon-remove
validating : glyphicon glyphicon-refresh
},
fields : {
myobject[].description : { // <---name of tag.
validators : {
notEmpty : {
message : 'this is required'
}
}
}
}
});
答案 0 :(得分:6)
在rails中,bootstrap验证器插件首先下载bootstrap-toggle-master文件并复制并通过项目中的validator.js或validator.min.js文件。
在视图中添加以下代码
{<%= form_tag({controller: "facebook", action: "post_message", method: "post"}, :data => {:toggle => "validator"},:class => "facebook-post") do %>
<div class="form-group">
<label for="exampleInputEmail1">Please write something for your status and our wall</label>
<%= text_area_tag :status_message, nil, class: "form-control", :rows => 3, :required => 'true', :data => {:error => "Please write something for both your status and our wall. E.g. Thanks very much for a great night."}%><div class="help-block with-errors"></div>
<% if @venue_location.present? %>
<small>- at </small><%= link_to @venue_location, @fb_page, target: '_blank' %>
<% end %>
</div>
<% if ((@package == 'package3') && !(@fb_page.blank?)) %>
<div class="facebook-like">
<div class="fb-like"
data-href="<%= current_venue.facebook_page %>"
data-layout="standard"
data-action="like"
data-show-faces="false"
style="overflow: hidden">
</div>
</div>
<% end %>
<div class="btn-next text-right">
<%= image_submit_tag("customer/icon-forward.png") %>
</div>
<% end %>}