最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ckeditor plugin dialog select get the description from the selected one - Stack Overflow

programmeradmin0浏览0评论

Im am developing a placeholder plugin to CKEDITOR and it´s basically plete. The problem I have is that I am trying to get the value and description from the select within the dialog and I am only getting the value. The array that contains the description and value looks like this

--> items: [['description1', 'value1'], ['description2', 'value2']] <--

In the return -> contents -> elements with ID dropdown I have setup and mit function. In these functions I need to get the description just like getting the name from select option.

Really need help with this one, thanks in advance

example -->

<select>
    <option value="value1">description1</option>
    <option value="value2">description2</option>
</select>

example <--

(function () {

    function placeholderDialog(editor, isEdit) {

        var lang = editor.lang.phlink,
            generalLabel = editor.langmon.generalTab;

        return {
            title: lang.title,
            minWidth: 300,
            minHeight: 80,
            contents: [
                {
                    id: 'info',
                    label: generalLabel,
                    title: generalLabel,
                    elements: [
                    {
                        id: 'dropdown'
                        , type: 'select'
                        , label: lang.chooseVal
                        , 'default': 'Detta är default'
                        , items: [['description1', 'value1'], ['description2', 'value2']]
                        , setup: function (data) {
                            // need the description
                            this.setValue(data.title);
                        }
                        , mit: function (data) {
                            // need the description
                            data.title = this.getValue();
                        }
                    },
                    {
                        id: 'text',
                        type: 'text',
                        style: 'width: 100%;',
                        label: lang.text,
                        'default': '',
                        required: true,
                        validate: CKEDITOR.dialog.validate.notEmpty(lang.textMissing),
                        setup: function (data) {
                            this.setValue(data.text);
                        },
                        mit: function (data) {
                            data.text = this.getValue();
                        }
                    }
                ]
                }
            ],
            onShow: function () {
                var data = { tag: 'link', content: "detta är innehåll", title: "Länk till svar", text: "detta är text" };
                if (isEdit) {
                    this._element = CKEDITOR.plugins.phlink.getSelectedPlaceHolder(editor);
                    data.title = this._element.getAttribute('title');
                    data.text = this._element.getText();
                    data.tag = this._element.getAttribute('data-jztag');
                }

                this.setupContent(data);
            },
            onOk: function () {
                var data = { tag: 'link', content: null, title: null, text: null };

                thismitContent(data);

                CKEDITOR.plugins.phlink.createPlaceholder(editor, this._element, data);

                delete this._element;
            }
        };
    }

    CKEDITOR.dialog.add('createplaceholder', function (editor) {
        return placeholderDialog(editor);
    });
    CKEDITOR.dialog.add('editplaceholder', function (editor) {
        return placeholderDialog(editor, 1);
    });
})();

Im am developing a placeholder plugin to CKEDITOR and it´s basically plete. The problem I have is that I am trying to get the value and description from the select within the dialog and I am only getting the value. The array that contains the description and value looks like this

--> items: [['description1', 'value1'], ['description2', 'value2']] <--

In the return -> contents -> elements with ID dropdown I have setup and mit function. In these functions I need to get the description just like getting the name from select option.

Really need help with this one, thanks in advance

example -->

<select>
    <option value="value1">description1</option>
    <option value="value2">description2</option>
</select>

example <--

(function () {

    function placeholderDialog(editor, isEdit) {

        var lang = editor.lang.phlink,
            generalLabel = editor.lang.mon.generalTab;

        return {
            title: lang.title,
            minWidth: 300,
            minHeight: 80,
            contents: [
                {
                    id: 'info',
                    label: generalLabel,
                    title: generalLabel,
                    elements: [
                    {
                        id: 'dropdown'
                        , type: 'select'
                        , label: lang.chooseVal
                        , 'default': 'Detta är default'
                        , items: [['description1', 'value1'], ['description2', 'value2']]
                        , setup: function (data) {
                            // need the description
                            this.setValue(data.title);
                        }
                        , mit: function (data) {
                            // need the description
                            data.title = this.getValue();
                        }
                    },
                    {
                        id: 'text',
                        type: 'text',
                        style: 'width: 100%;',
                        label: lang.text,
                        'default': '',
                        required: true,
                        validate: CKEDITOR.dialog.validate.notEmpty(lang.textMissing),
                        setup: function (data) {
                            this.setValue(data.text);
                        },
                        mit: function (data) {
                            data.text = this.getValue();
                        }
                    }
                ]
                }
            ],
            onShow: function () {
                var data = { tag: 'link', content: "detta är innehåll", title: "Länk till svar", text: "detta är text" };
                if (isEdit) {
                    this._element = CKEDITOR.plugins.phlink.getSelectedPlaceHolder(editor);
                    data.title = this._element.getAttribute('title');
                    data.text = this._element.getText();
                    data.tag = this._element.getAttribute('data-jztag');
                }

                this.setupContent(data);
            },
            onOk: function () {
                var data = { tag: 'link', content: null, title: null, text: null };

                this.mitContent(data);

                CKEDITOR.plugins.phlink.createPlaceholder(editor, this._element, data);

                delete this._element;
            }
        };
    }

    CKEDITOR.dialog.add('createplaceholder', function (editor) {
        return placeholderDialog(editor);
    });
    CKEDITOR.dialog.add('editplaceholder', function (editor) {
        return placeholderDialog(editor, 1);
    });
})();
Share Improve this question asked Mar 18, 2013 at 15:48 JohannesAnderssonJohannesAndersson 4,6302 gold badges18 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Use the following to get option's text:

var input = this.getInputElement().$;
console.log( input.options[ input.selectedIndex ].text );
>> "description1"
发布评论

评论列表(0)

  1. 暂无评论