在 text_field 中添加 name 属性时,数据不会被提交,当我删除 name 属性时,它会被很好地提交,但 jquery 验证不起作用。我正在使用 jquery formvalidation.io 插件进行验证,我想在 text_field 中添加一个自定义名称属性以进行验证。到目前为止,我发现很难理解,我尝试在 text_field 中添加这样的“'name'=>'test'”,但没有用,希望有人能提出解决方案,以便 jquery 验证和数据提交都能正常工作,谢谢。
这是我的 HTML
<section class="content">
<%= form_for(tbl_ad_test_overview, :html => {:class => "form-online", :id => "form", :style => "margin-left: 15px; width: 95%;"}) do |f|%>
<div class="form-group">
<%= f.label :test, 'Test Number *', class: 'font-color' %>
<%= f.text_field :test, id: 'test', name:'test', placeholder: 'Test Number', class: 'form-control'%>
<br>
</div>
<div class="form-group">
<div class="col-lg-12 col-xs-offset-5">
<%= f.submit "Submit", id: 'validate', class: 'btn btn-primary'%>
</div>
</div>
<% end %>
</section>
这是我的jQuery
$(document).ready(function() {
$('#validate').on('click', function(event) {
$('#form').formValidation({
framework : 'bootstrap',
icon : {
valid : 'glyphicon glyphicon-ok',
invalid : 'glyphicon glyphicon-remove',
validating : 'glyphicon glyphicon-refresh'
},
fields : {
test : {
validators : {
notEmpty : {
message : 'Please enter a positive number greater than 0'
},
stringLength : {
min : 1,
message : 'Please do enter at least 1 number'
},
}
}
}
});
});
});
这是控制器中的必需参数
def tbl_ad_test_overview_params
params.require(:tbl_ad_test_overview).permit(:test)
end