3 * @class Roo.bootstrap.form.MultiLineTag
4 * @param {Object} config The config object
8 Roo.bootstrap.form.MultiLineTag = function(config){
9 Roo.bootstrap.form.MultiLineTag.superclass.constructor.call(this, config);
14 * Fires before a request is made for a new data object. If the beforeload handler returns false
15 * the load action will be canceled.
16 * @param {Roo.boostrap.form.MultiLineTag} this
17 * @param {Store} store
18 * @param {Object} options The loading options that were specified (see {@link #load} for details)
24 Roo.extend(Roo.bootstrap.form.MultiLineTag, Roo.bootstrap.form.Input, {
36 // for combo box store
42 getAutoCreate : function()
45 cls : 'roo-multi-line-tag form-group'
48 config = this.getAutoCreateLabel( config, {
49 cls : 'roo-multi-line-tag-container'
55 initEvents : function()
59 for (var i = 0; i < this.minimumRow; i++) {
64 addTagRow : function()
68 var comboBox = Roo.factory({
69 xns: Roo.bootstrap.form,
73 minChars: _this.minChars,
74 displayField: _this.displayField,
75 valueField : _this.valueField,
76 listWidth: _this.listWidth,
77 placeholder : _this.placeholder,
78 queryParam : _this.queryParam,
83 beforeload : function(_self, options)
85 _this.fireEvent('beforeload', _this, _self, options);
101 'render' : function (_self) {
102 _self.inputEl().on('keyup', function(e) {
103 if(_this.shouldAutoAddTagRow()) {
107 _self.inputEl().on('change', function(e) {
108 _this.fireEvent('change', _this, _this.getValue(), false);
109 _this.showHideRemoveBtn();
113 'select' : function(_self, record, index) {
114 _this.fireEvent('change', _this, _this.getValue(), false);
119 var button = Roo.factory({
133 'render' : function (_self) {
134 this.inputCb = comboBox;
135 this.removeBtn = button;
137 this.removeBtn.on('click', function() {
138 _this.removeTagRow(_self);
139 _this.fireEvent('change', _this, _this.getValue(), false);
144 this.tagRows.push(this.addxtype(row));
146 _this.showHideRemoveBtn();
149 // a new tags should be added automatically when all existing tags are not empty
150 shouldAutoAddTagRow : function()
154 Roo.each(this.tagRows, function(r) {
155 if(r.inputCb.getRawValue() == '') {
163 removeTagRow : function(row)
166 this.tagRows.splice(this.tagRows.indexOf(row), 1);
167 this.showHideRemoveBtn();
170 // hide all remove buttons if there are {minimumRow} or less tags
171 // hide the remove button for empty tag
172 showHideRemoveBtn : function()
176 Roo.each(this.tagRows, function (r) {
180 if(_this.tagRows.length <= _this.minimumRow || r.inputCb.getRawValue() == '') {
186 getValue : function()
190 Roo.each(_this.tagRows, function(r) {
191 var value = r.inputCb.getRawValue();
194 tag[_this.valueField] = r.inputCb.getRawValue();
199 return JSON.stringify(tags);
202 setValue : function(json)
205 // remove all old tags
206 var oldTotal = this.tagRows.length;
208 for(var i = 0; i < oldTotal; i ++) {
209 this.removeTagRow(this.tagRows[0]);
212 // empty tag if invalid json
217 arr = JSON.parse(json);
221 for (var i = 0; i < arr.length; i ++) {
223 this.tagRows[i].inputCb.setRawValue(arr[i][this.valueField]);
226 // always add one extra empty tag
229 // add empty tags until there are {minimumRow} tags
230 while(this.tagRows.length < this.minimumRow) {
236 getChildContainer : function()
238 return Roo.select('.roo-multi-line-tag-container', true).elements[0];