Using
bootstrap3-wysihtml5-bower 2013-11-22 (WYSIWYG Editor)
and
BootstrapValidator v0.5.2
Validate textarea(bootstrap-wysihtml5 editor) using bootstrap validation. Just need to check NotEmpty and Max Characters then submit Form.
So far tried
$('#setpolicyform').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
ignore: ":hidden:not(textarea)",
fields: {
policyta: {
group: '.lnbrd',
validators: {
notEmpty: {
message: 'Textarea cannot be empty'
}
}
}
}
}).on('success.form.bv', function(e) {
e.preventDefault();
var $form = $("#setpolicyform"),
$url = $form.attr('action');
$.post($url, $form.serialize()).done(function(dte) {
$("#policy-content").html(dte);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form role="form" method="POST" action="self.php" name="setpolicyform" id="setpolicyform">
<div class='box-body pad'>
<div class="form-group">
<div class="lnbrd">
<textarea class="form-control textarea" name="policyta" placeholder="Place some text here" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
</div>
</div>
</div>
<div class="box-footer clearfix">
<button type="submit" class="btn btn-danger pull-right" id="setpolicyformsubmitbtn"><i class="fa fa-save"></i> SAVE</button>
</div>
</form>
There is a way to validate the
WYSIWYG Editor, reasonbootstrapValidatornot validating it because after initializingWYSIWYG Editoron textareaname="policyta", it will be hidden and ignored bybootstrapValidatorSo the one way is do not hide the
textarea, just setz-index: -1and it will go behind theWYSIWYG Editor, useWYSIWYG Editoreventloadto add the CSS after initializing,CSS
JS
Now let's validate the textarea with
bootstrapValidatorand you also asked forMax CharacterslimitFirst
bootstrapValidatorscriptNow let's check and validate the textarea with
bootstrapValidator, need anotherwysihtml5eventchangeto check the changes and re-validateSo the Final Script will be
Fiddle Working Example