3

i installed ckeditor from https://github.com/2amigos/yii2-ckeditor-widget on my Yii 2 advanced platform.

Installation is successful. However when i click submit, it is not passing through the validation check and will state "Description cannot be blank" even though there is content inside. When i click submit button for the second time, the data got through.

Inside rules in model this field is required. When i remove ckeditor and directly use

<?php echo $form->field($model, 'MY_DESC'); ?>

it got through on first submit.

Can anyone kindly help?

Thanks in advance.

esiaz
  • 619
  • 4
  • 10
  • 22

2 Answers2

5

This happens because of the way such plugins work. It generates extra HTML markup leaving the actual textarea hidden and empty. It will be filled at the moment of submitting form.

Most likely you are using client validation (which is enabled by default). It's obviously checking textarea directly and don't know anything where real content is stored.

Either disable it in your form like so:

<?php ActiveForm::begin(['enableClientValidation' => false]); ?>

Or look for some ways of synchronization with textarea.

Take a look for example at this question but I don't know if it will work in version you are using with that Yii2 extension.

Maybe some more advanced options exist now so you don't have to write it by yourself.

Community
  • 1
  • 1
arogachev
  • 33,150
  • 7
  • 114
  • 117
  • 1
    sorry i tried to up vote but it says requires 15 reputation and i still at 14.. will do it once i reach 15! – esiaz Jan 21 '15 at 05:15
3

You can probably use the following solution (untested):

$('#myform').on('beforeValidate', function (event, messages, deferreds) {
    for(var instanceName in CKEDITOR.instances) { 
        CKEDITOR.instances[instanceName].updateElement();
    }
    return true;
}

Based on Yii 1 solution: https://stackoverflow.com/a/28876719/729324

Converted according to: https://github.com/yiisoft/yii2/blob/95cdd0905d26bf9e64211238b4a2a698d8d047d2/framework/UPGRADE.md

Community
  • 1
  • 1
marcovtwout
  • 5,230
  • 4
  • 36
  • 45