editors

webix.editors

webix.editors helper.

Please look into the linked official documentation.

Referenced by

mixins
EditAbility().

External references

Official documentation page.

Code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
webix.editors = {
    "text":{
        focus:function(){
            this.getInputNode(this.node).focus();
            this.getInputNode(this.node).select();
        },
        getValue:function(){
            return this.getInputNode(this.node).value;
        },
        setValue:function(value){
            var input = this.getInputNode(this.node);
            input.value = value;

            init_suggest(this, input);
        },
        getInputNode:function(){
            return this.node.firstChild;
        },
        render:function(){
            return webix.html.create("div", {
                "class":"webix_dt_editor"
            }, "<input type='text' aria-label='"+getLabel(this.config)+"'>");
        }
    },
    "inline-checkbox":{
        render:function(){ return {}; },
        getValue:function(){
            return this.node.checked;
        },
        setValue:function(){},
        focus:function(){
            this.node.focus();
        },
        getInputNode:function(){},
        $inline:true
    },
    "inline-text":{
        render:function(){ return {}; },
        getValue:function(){
            return this.node.value;
        },
        setValue:function(){},
        focus:function(){
            try{    //IE9
                this.node.select();
                this.node.focus();
            } catch(e){}
        },
        getInputNode:function(){},
        $inline:true
    },
    "checkbox":{
        focus:function(){
            this.getInputNode().focus();
        },
        getValue:function(){
            return this.getInputNode().checked;
        },
        setValue:function(value){
            this.getInputNode().checked = !!value;
        },
        getInputNode:function(){
            return this.node.firstChild.firstChild;
        },
        render:function(){
            return webix.html.create("div", {
                "class":"webix_dt_editor"
            }, "<div><input type='checkbox' aria-label='"+getLabel(this.config)+"'></div>");
        }
    },
    "select":{
        focus:function(){
            this.getInputNode().focus();
        },
        getValue:function(){
            return this.getInputNode().value;
        },
        setValue:function(value){
            this.getInputNode().value = value;
        },
        getInputNode:function(){
            return this.node.firstChild;
        },
        render:function(){
            var html = "";
            var options = this.config.options || this.config.collection;
            webix.assert(options,"options not defined for select editor");

            if (options.data && options.data.each)
                options.data.each(function(obj){
                    html +="<option value='"+obj.id+"'>"+obj.value+"</option>";
                });
            else {
                if (webix.isArray(options)){
                    for (var i=0; i<options.length; i++){
                        var rec = options[i];
                        var isplain = webix.isUndefined(rec.id);
                        var id = isplain ? rec : rec.id;
                        var label = isplain ? rec : rec.value;

                        html +="<option value='"+id+"'>"+label+"</option>";
                    }
                } else for (var key in options){
                    html +="<option value='"+key+"'>"+options[key]+"</option>";
                }
            }

            return webix.html.create("div", {
                "class":"webix_dt_editor"
            }, "<select aria-label='"+getLabel(this.config)+"'>"+html+"</select>");
        }
    },
    popup:{
        focus:function(){
            this.getInputNode().focus();
        },
        destroy:function(){
            this.getPopup().hide();
        },
        getValue:function(){
            return this.getInputNode().getValue()||"";
        },
        setValue:function(value){
            this.getPopup().show(this.node);
            this.getInputNode().setValue(value);
        },
        getInputNode:function(){
            return this.getPopup().getChildViews()[0];
        },
        getPopup:function(){
            if (!this.config.popup)
                this.config.popup = this.createPopup();

            return webix.$$(this.config.popup);
        },
        createPopup:function(){
            var popup = this.config.popup || this.config.suggest;

            if (popup){
                var pobj;
                if (typeof popup == "object" && !popup.name){
                    popup.view = popup.view || "suggest";
                    pobj = webix.ui(popup);
                } else
                    pobj = webix.$$(popup);

                if (pobj.linkInput)
                    pobj.linkInput(document.body);
                else if(this.linkInput)
                    this.linkInput(document.body);

                return pobj;
            }

            var type = webix.editors.$popup[this.popupType];
            if (typeof type != "string"){
                type = webix.editors.$popup[this.popupType] = webix.ui(type);
                this.popupInit(type);

                if(!type.linkInput)
                    this.linkInput(document.body);

            }
            return type._settings.id;
        },
        linkInput:function(node){
            webix._event(webix.toNode(node), "keydown", webix.bind(function(e){
                var code = e.which || e.keyCode, list = this.getInputNode();
                if(!list.isVisible()) return;

                if(code === 40){
                    if(list.moveSelection)
                        list.moveSelection("down");
                    webix.UIManager.setFocus(list);
                }
                else if(code === 13)
                    webix.callEvent("onEditEnd", []);

            }, this));
        },

        popupInit:function(popup){},
        popupType:"text",
        render    :function(){ return {}; },
        $inline:true
    }
};