Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to define events with package verion 3.0.4 #35

Open
glevolod opened this issue Aug 23, 2019 · 2 comments
Open

how to define events with package verion 3.0.4 #35

glevolod opened this issue Aug 23, 2019 · 2 comments

Comments

@glevolod
Copy link

I'm using widget as described in documentation. Didn't find how to define events in widget.
So tried such way:

echo \froala\froalaeditor\FroalaEditorWidget::widget([
    'name' => 'content',
    'value' => 'initial text',
    'options' => [
        // html attributes
        'id' => "froala-editor-id",
    ],
    'clientOptions' => [
        'toolbarInline'=> false,
        'attribution' => false,
        'toolbarButtons' => [
            'moreText'      => [
                'buttons' => ['clear', 'insert', 'bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', 'fontFamily',
                    'fontSize', 'textColor', 'backgroundColor', 'inlineClass', 'inlineStyle', 'clearFormatting'],
                'buttonsVisible' => 5,
            ],
        ],
        'theme' =>'royal', //optional: dark, red, gray, royal
        'language'=>'en_gb', // optional: ar, bs, cs, da, de, en_ca, en_gb, en_us ...
        'saveParam' => 'content',
        'saveURL' => 'http://example.com/save',
        'saveMethod' =>  'POST',
        'saveParams' => ['id' => 'my_editor'],
        'events' => [
          'save.before' => 'function () {console.log("save.before");}',
        ],
    ],
    'clientPlugins' => [
        'align', 'char_counter', 'code_beautifier', 'code_view', 'colors',
        'draggable', 'emoticons', 'entities', 'file', 'font_family',
        'font_size', 'fullscreen', 'image', 'image_manager', 'inline_style',
        'line_breaker', 'link', 'lists', 'paragraph_format', 'paragraph_style',
        'quick_insert', 'quote', 'save', 'table', 'url', 'video', 'help', 'print',
        'special_characters', 'word_paste',
    ],
]);

But it returns an error in browser console when I trigger save() event with 'clear' button.
Button declaration :

  FroalaEditor.DefineIcon('clear', {NAME: 'remove', SVG_KEY: 'remove'});
  FroalaEditor.RegisterCommand('clear', {
    title: 'Clear HTML',
    focus: false,
    undo: true,
    refreshAfterCallback: true,
    callback: function (button) {
      this.html.set('');
      this.save.save();
    }
  });

Error from browser console:

Uncaught TypeError: l.opts.events[e].apply is not a function
    at Object.v [as trigger] (froala_editor.min.js?v=1566469764:formatted:809)
    at Object.a [as save] (eval at globalEval (jquery.js?v=1566403370:343), <anonymous>:7:571)
    at E.Bootstrap.callback (eval at globalEval (jquery.js?v=1566403370:343), <anonymous>:33:17)
    at Object.n [as exec] (froala_editor.min.js?v=1566469764:formatted:1187)
    at i (froala_editor.min.js?v=1566469764:formatted:5698)
    at r (froala_editor.min.js?v=1566469764:formatted:5710)
    at t (froala_editor.min.js?v=1566469764:formatted:5711)
    at E.Bootstrap.c (froala_editor.min.js?v=1566469764:formatted:5715)
    at o (froala_editor.min.js?v=1566469764:formatted:931)
    at HTMLButtonElement.<anonymous> (froala_editor.min.js?v=1566469764:formatted:936)

Please explain how to define events when using FroalaEditorWidget for Yii2 php framework

@cshehadi
Copy link
Contributor

I got this error as well, and was able to fix it with:

'events' => [
'save.before' => new \yii\web\JsExpression('function () {console.log("save.before");}'),
],

@ghost
Copy link

ghost commented Apr 12, 2020

I got this error as well, and was able to fix it with:

'events' => [
'save.before' => new \yii\web\JsExpression('function () {console.log("save.before");}'),
],

You can use it in this way :-

echo \froala\froalaeditor\FroalaEditorWidget::widget([
    'model' => $model,
    'attribute' => $attribute,
    'id' => !empty($unique_id) ? $unique_id : 'description-body',
    'clientOptions' => [
        'events' => [
            'contentChanged' => new \yii\web\JsExpression('function () {console.log("contentChanged");}')
        ],
............

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants