2017-02-24 65 views
0

我正在使用CKEDITOR placeholder plugin並嘗試在onClick上設置小部件數據。如何在onClick事件中設置CKEDITOR對話框數據

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

但是當我嘗試做同樣的的onClick:

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

widget對象是不同的,widget.setData是不確定的,當我設置上提交控件數據

,一切工作正常。

我的問題是如何在radio元素上設置onClick事件的widget數據?

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) { 

        } 
       } 
      ] 
     }] 
    }; 
}); 

回答

0

爲了使它在onClick事件,工作簡單地添加

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

的onClick函數中這樣

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