$('.class').trumbowyg('html') method returning "false" even when content is in the editor
See original GitHub issueFirst of all, thanks for Trumbowyg. It’s great. I think I may have found a bug but I don’t want to do a pull request until I understand what’s happening. We have a form with trumbowyg instances and the validation is a standard if (content) { $.post() } else { alert(“No content”); } A user submitted a bug report that they were getting the no content message even when they had content in the editor.
So, I went to the trumbowyg.js code (which is very clean and readable and I thank you for that) and did some debugging. It turned out, the ‘html’ method was never firing because on line 72, it fails this test
if(this.length === 1){
I didn’t have two textareas in my HTML code so I added console.log(this) to debug. Turns out, this had 2 textareas, the orginal textarea and a hidden one created by trumbowyg. If I just removed the 2nd element like this:
if (this.length === 2) {
this.splice(1,1)
}
everything worked. The working version is here. Normally, I would do a pull request and add that as a bug fix but just splicing the 2nd element off the array doesn’t address why it has a 2nd element in the first place.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
For anyone who is struggling with this, this was my solution in my own case. My mistake was:
$('.trumbowyg').trumbowyg('html');
This class is already used in the Trumbowyg plugin, so I inadvertently selected multiple targets, which is why it was returning false.