- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 this library和 jquery.validate 库,我遇到了样式问题:通常错误应该在选择列表下。
我的 JS 代码:
errorElement: 'p',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.form-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
},
highlight: function(element) {
$(element).closest(".form-group").addClass("has-error").removeClass("has-success");
$(element).parent().find('.form-control-feedback').removeClass('glyphicon-ok').addClass('glyphicon-remove');
},
unhighlight: function(element) {
$(element).closest(".form-group").removeClass("has-error").addClass("has-success");
$(element).parent().find('.form-control-feedback').removeClass('glyphicon-remove').addClass('glyphicon-ok');
},
HTML 代码:
<div class="form-group has-feedback">
<label for="brands" class="col-sm-2">Brand :</label>
<div class="col-sm-9">
{!! Form::select('brands', $brandsArray, 'default' , ['class' => 'form-control combobox', 'id'=>'brands']) !!}
</div>
<div class="col-sm-1">
<!-- <a href="#" title="Add new brand" data-toggle="modal" data-target="#brandModal"><i class="fa fa-plus"></i></a> -->
<button type="button" class="btn btn-xs" title="Add new brand" id="addBrandLogo"><i class="fa fa-plus"></i></button>
</div>
</div>
有错误的 HTML 代码:
<div class="col-sm-9">
<select name="brands" id="brands" class="form-control combobox select2-hidden-accessible" tabindex="-1" aria-hidden="true" aria-required="true" aria-describedby="brands-error" aria-invalid="true"><option selected="selected" value="">...</select>
<p id="brands-error" class="help-block">Please enter brand name</p>
<span class="select2 select2-container select2-container--default" dir="ltr" style="width: 497px;"><span class="selection">...</span></span>
</div>
最佳答案
这是我解决问题的代码:
errorPlacement: function(error, element) {
if(element.parent('.form-group').length) {
error.insertAfter(element.parent());
} else {
//check if the element name is the select2 input
if (element.attr('name') == "brands")
//instead of insetring after the element directly
// insert the error after the next tag of element, after the select2 span.
error.insertAfter(element.next());
else
error.insertAfter(element);
}
},
关于javascript - Select2 & JqueryValidator 样式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014929/
我正在使用 jQueryValidation我想验证我的表单而不需要使用 name属性。 如果表单元素没有 name属性仅验证第一个元素。 jQuery Validati
我正在使用jquery验证插件来验证我的表单数据,我有一个fileupload元素,然后有一个按钮,它打开浏览窗口来选择文件,因为默认错误消息显示在fileuplad元素和按钮之间,我想显示这个按钮后
如何在不覆盖所有验证设置的情况下覆盖 jQueryvalidation 对象的提交处理程序? form1.validate({ focusInvalid: false, // do not
我正在使用 this library和 jquery.validate 库,我遇到了样式问题:通常错误应该在选择列表下。 我的 JS 代码: errorElement: 'p', er
我正在使用 http://jqueryvalidation.org 这非常有效 http://jsfiddle.net/xs5vrrso/ jQuery $(document).ready(funct
我想使用 jQuery.validator require_from_group 方法验证多个 select2 元素。当我提交表单而不选择任何值时,验证有效。但是在更改任何 select2 元素中的值
我正在尝试通过ajax提交表单,它工作正常,但没有验证。因此,我添加了 JQuery 验证库并将代码添加到处理程序中,如文档中所述,但它似乎没有执行 cshtml 页面: @{ ViewDat
我是一名优秀的程序员,十分优秀!