Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE required prevent from sending form

I have a problem with TinyMCE. In my application based on CakePHP v3 I have a form to add loyalty tasks. There is a field which uses tinymce to describe task.

So the problem is when I fill the form with data and click on submit button nothing happen. What is more there is the form to edit tasks too and it works perfectly(is exactly the same). No custom JS is added for problematic form.

I know that TinyMCE with require on textarea cause the problem, because when I disable required it works perfectly.

Some code:
TinyMCE initialization:

tinymce.init({
    selector: 'textarea.tinymce',
    height: 500,
    plugins: [
        "advlist autolink link image lists charmap preview hr anchor image",
        "wordcount visualblocks visualchars fullscreen insertdatetime nonbreaking",
        "table paste"
    ],
    toolbar1: "undo redo cut copy paste | bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright alignjustify | table",
    toolbar2: "formatselect | outdent indent | bullist numlist | blockquote link unlink charmap hr image | preview",
    menubar: false,
    content_css: [
        '//www.tinymce.com/css/codepen.min.css'
    ]
});

Form(removed few elements):

<?= $this->Form->create(null, ['enctype'=>'multipart/form-data']); ?>
<div class="col-xs-12">
    <div class="form-group">
        <label>Tytuł</label>
        <input type="text" name="title" class="form-control" required="required"/>
    </div>
</div>
//additional elements
<div class="col-xs-12">
    <div class="form-group">
        <label>Treść zadania</label>
        <textarea name="task" class="form-control tinymce" required="required"></textarea>
    </div>
    <input type="submit" class="" value="Dodaj"/>
</div>
<?= $this->Form->end(); ?>

Used version of TinyMCE: 4.6.4(newest)

like image 285
Manveru Avatar asked Jul 12 '17 09:07

Manveru


1 Answers

Thanks for fast replies, but I found answer by myself on tinymce support forum.

For others who will have this problem: just add code below to your tinyMCE initialization.

setup: function (editor) {
    editor.on('change', function (e) {
        editor.save();
    });
}
like image 80
Manveru Avatar answered Sep 20 '22 13:09

Manveru