admin管理员组文章数量:1391969
I have a ment form that is showing also the bootstrap help-block as:
<p class="help-block">required</p>
I want this p
to be hidden except when the form is submitted and the field is validated as an error.
when the form is submitted with an error, the parent <div class="form-group">...</div>
gets an additional has-error
class. How could I show the help-block
only if there is an error in the form submission? Btw I have no access to the HTML...
I have a ment form that is showing also the bootstrap help-block as:
<p class="help-block">required</p>
I want this p
to be hidden except when the form is submitted and the field is validated as an error.
when the form is submitted with an error, the parent <div class="form-group">...</div>
gets an additional has-error
class. How could I show the help-block
only if there is an error in the form submission? Btw I have no access to the HTML...
1 Answer
Reset to default 6CSS way
.help-block { display: none; }
.form-group.has-error .help-block { display: block; }
jQuery way
$('.help-block').hide();
$('#yourForm').submit(function(){
$.each($(this).find('.form-group'), function(){
// Long but clear version
if ( $(this).hasClass('has-error') ) {
$(this).find('.help-block').show();
} else {
$(this).find('.help-block').hide();
}
// Shortest version
// $(this).find('.help-block')[ $(this).hasClass('has-error') ? 'show' : 'hide' ]();
});
});
本文标签: javascriptbootstrap helpblock to show only if formgroup haserrorStack Overflow
版权声明:本文标题:javascript - bootstrap help-block to show only if form-group has-error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744740306a2622567.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论