Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation in Bootstrap wysiwyg5 editor

I am using Bootstrap wysiwyg5 editor as a part of a form.

This text area happens to be a required field(should not be empty). I want to validate if the user has entered any value on to this field or not. I see that Bootstrap wysiwyg uses a Iframe to display the content. I tried to access the content of the iframe's body in jQuery by doing this:

$('.textarea.wysihtml5-editor').html()

but failed.

My question is: How do I check if the user has entered some text in this Bootstrap wysiwyg textarea. Please help me out.

PS: I saw this question, but it was not very helpful.

like image 308
codeMan Avatar asked May 16 '13 12:05

codeMan


People also ask

How do I add a WYSIWYG editor to a bootstrap page?

Add the WYSIWYG editor to your Bootstrap project The TinyMCE editor initializes on a specified element on your page, so let’s first create a basic form, including a textarea where the editor will go. To do this, replace <h1>Hello, world!</h1> (in the body) with the following code:

What is sortable bootstrap WYSIWYG editor?

Bootstrap WYSIWYG Editor is a lightweight plugin that enables rich text editing on your website. To start working with sortable plugin see "Getting Started" tab on this page. Note: This documentation is for an older version of Bootstrap (v.4).

How to use custom translations in Bootstrap WYSIWYG editor?

Bootstrap WYSIWYG Editor comes with the option that allows you to use custom translations for all text in the editor. By default, Bootstrap WYSIWYG Editor use color palette from MDBootstrap's text colors. If you need to use your custom colors, you can simply customize them to fit your project.

How to use custom colors in Bootstrap WYSIWYG editor?

By default, Bootstrap WYSIWYG Editor use color palette from MDBootstrap's text colors. If you need to use your custom colors, you can simply customize them to fit your project.


4 Answers

I know the question is old, but maybe help somebody looking for this..

To make the JQuery Validation work with WysiHtml5, just set the plugin to not ignore hidden textareas:

$('#form').validate({
   ignore: ":hidden:not(textarea)",     
   rules: {     
       WysiHtmlField: "required"
   },
   submitHandler: function(form) { ... }
});
like image 82
Fabi Curti Avatar answered Oct 21 '22 17:10

Fabi Curti


you need to listen for the blur event then check the editor.textareaElement of the editor to get the underlying textarea.

var editor = new wysihtml5.Editor("wysihtml5-editor");

editor.on('blur', function() {
    if( this.textareaElement.value.length === 0 ) { alert('no blank entries!'); }
});

Most of this info is on their wiki: https://github.com/xing/wysihtml5/wiki

like image 38
rlemon Avatar answered Oct 21 '22 18:10

rlemon


you are using bootstrap-wysihtml5 and rlemon answered you with the code for the regular non bootstrap-themed WYSIHTML5.

your

var editor = new wysihtml5.Editor("wysihtml5-editor");

code is actually inside bootstrap-wysihtml5-0.0.2.js (or whatever version you used)

however this wrapper defines the editor object as window.editor so you can create your blur function like this , after you initiate you wysihtml5 element.

window.editor.on('blur', function() {
 // do whatever you want to do on blur
});
like image 1
NadavSinai Avatar answered Oct 21 '22 19:10

NadavSinai


I think I found a solution, by jquery we are adding nicehide class to our wysihtml5, now we can validate it, I hide it with visibility hidden, maybe ur code could without it, other solution could be put iframe class and nicehide to same position...

jQuery('.wysihtml5').wysihtml5({
"events":      {
"load": function () {
jQuery('.wysihtml5').addClass('nicehide');
}
}
});


.nicehide {
resize: none;
display: block !important;
width: 0;
height: 0;
margin: -200px 0 0 0;
float: left;
visibility:hidden;
}

Thanks to https://github.com/jhollingworth/bootstrap-wysihtml5/issues/275 , I only added visibility..

like image 1
Mehmet Uyarovic Avatar answered Oct 21 '22 17:10

Mehmet Uyarovic