简体   繁体   English

如何在onClick事件上设置CKEDITOR对话框数据

[英]How to set CKEDITOR dialog data on onClick event

I am working with CKEDITOR placeholder plugin and trying to set widget data on onClick. 我正在使用CKEDITOR 占位符插件,并尝试在onClick上设置小部件数据。

Everything works fine when I set widget data on commit: 当我在提交时设置小部件数据时,一切工作正常:

commit: function(widget) {
  widget.setData('name', this.getValue());
}

But when I try to do the same on onClick: 但是,当我尝试在onClick上执行相同操作时:

onClcik: function(widget) {
    widget.setData('name', this.getValue());
 }

my widget object is different and widget.setData is undefined. 我的widget对象不同, widget.setData未定义widget.setData

My question is how to set widget data on onClick event on radio element? 我的问题是如何在单选元素的onClick事件上设置小部件数据?

Placholder.js Placholder.js

'use strict';
CKEDITOR.dialog.add('placeholder', function(editor) {
    var lang = editor.lang.placeholder,
        generalLabel = editor.lang.common.generalTab,
        validNameRegex = /^[^\[\]<>]+$/;

    return {
        title: 'Insert variable from:',
        minWidth: 200,
        minHeight: 151,
        contents: [{
            id: 'initial-view',
            label: 'view one',
            title: generalLabel,
            elements: [{
                id: 'view-one',
                style: 'width: 100%;',
                type: 'html',
                html: ''
            }, {
                type: 'button',
                id: 'open-organizational-units',
                label: 'Organizational units',
                title: 'Organizational units',
                className: 'dialog-btn-icon-forward',
                setup: function(widget) {
                    this.setValue(widget.data.name);
                },
                onClick: function(widget) {
                    this.getDialog()
                        .selectPage('organizational-unit-view');
                }
            }]
        }, {
            id: 'organizational-unit-view',
            label: 'view two',
            title: generalLabel,
            elements: [{
                    type: 'button',
                    id: 'back-to-main-view',
                    label: 'Organizational units',
                    title: 'Organizational units',
                    className: 'dialog-btn-icon-back',
                    setup: function(widget) {
                        this.setValue(widget.data.name);
                    },
                    onClick: function(widget) {
                        this.getDialog()
                            .selectPage('initial-view');
                    }
                },
                {
                    type: 'radio',
                    id: 'list-of-vars',
                    align: 'vertical',
                    style: 'color: green',
                    'default': '',
                    setup: function(widget) {
                        this.setValue(widget.data.name);
                    },
                    onClick: function(widget) {
                        widget.setData('name', this.getValue());
                    },
                    commit: function(widget) {

                    }
                }
            ]
        }]
    };
});

To make it work on onClick event simply add 要使其适用于onClick事件,只需添加

var okBtn = document.getElementsByClassName('cke_dialog_ui_button_ok');
okBtn[0].click();

inside onClick function like this 里面像这样的onClick函数

onClick: function(widget) {
                    if (this.getValue()) {
                        var okBtn = document.getElementsByClassName('cke_dialog_ui_button_ok');
                        okBtn[0].click();
                    }
                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM