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' ]();
});
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744740307a4590986.html
评论列表(0条)