I'm using WYMeditor for this project. However, I have server side validation that checks that a textarea box is non-empty before it saves the data. But when using WYMeditor, it is inserting a <br />
tag even though I haven't even done so much as click inside the editor.
I searched around regarding this problem and found that it was labelled as a bug, here. But it was said to be fixed. However it's definitely still affecting me, even though I have downloaded and am using the latest stable version.
This is my code for inserting the textarea (I'm using CakePHP):
echo $this->Form->create('News', array('type' => 'file'));
echo $this->Form->input('News.title', array('label' => '*Title:'));
echo $this->Form->input('News.body', array('label' => '*Body:', 'class' => 'wymeditor'));
echo $this->Form->input('News.picture', array('label' => 'Picture:', 'type' => 'file'));
echo $this->Form->end(array('label' => 'Save News', 'class' => 'wymupdate'));
And my javascript for the textarea:
jQuery('.wymeditor').wymeditor({
skin: 'silver',
toolsItems: [
{'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'},
{'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
{'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
{'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
{'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
{'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
{'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
{'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
{'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'}
]
});
I have tested this not using the wymeditor javascript, but all my other javascript, and it functions as expected, so I suspect something is going on with the wymeditor javascript, but I'm unsure as to what.
I can think of a couple of possible reasons for these symptoms:
You could be using an old version of WYMeditor where this bug was present. Which version are you using? As of this writing, the current version is 1.0.0b3. You can test against WYMeditor master here.
If you're submitting the form without using the form's submit handler, then the wymupdate
class won't work, and you won't get the implicit wym.xhtml()
call, which means that some necessary HTML cleanup might not occur. You could try calling xhtml()
on your WYMeditor instance (you can retrieve it with jQuery.wymeditors(0)
if you only have one wymeditor).
If you can provide an example page, or a bit more info, I will update this answer accordingly.