Roo/bootstrap/ComboBox.js
[roojs1] / Roo / bootstrap / ComboBox.js
index f5a02a7..08b7336 100644 (file)
@@ -27,66 +27,66 @@ Roo.bootstrap.ComboBox = function(config){
         /**
          * @event expand
          * Fires when the dropdown list is expanded
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        */
         'expand' : true,
         /**
          * @event collapse
          * Fires when the dropdown list is collapsed
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        */
         'collapse' : true,
         /**
          * @event beforeselect
          * Fires before a list item is selected. Return false to cancel the selection.
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            * @param {Roo.data.Record} record The data record returned from the underlying store
-            * @param {Number} index The index of the selected item in the dropdown list
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        * @param {Roo.data.Record} record The data record returned from the underlying store
+        * @param {Number} index The index of the selected item in the dropdown list
+        */
         'beforeselect' : true,
         /**
          * @event select
          * Fires when a list item is selected
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
-            * @param {Number} index The index of the selected item in the dropdown list
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
+        * @param {Number} index The index of the selected item in the dropdown list
+        */
         'select' : true,
         /**
          * @event beforequery
          * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
          * The event object passed has these properties:
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            * @param {String} query The query
-            * @param {Boolean} forceAll true to force "all" query
-            * @param {Boolean} cancel true to cancel the query
-            * @param {Object} e The query event object
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        * @param {String} query The query
+        * @param {Boolean} forceAll true to force "all" query
+        * @param {Boolean} cancel true to cancel the query
+        * @param {Object} e The query event object
+        */
         'beforequery': true,
          /**
          * @event add
          * Fires when the 'add' icon is pressed (add a listener to enable add button)
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        */
         'add' : true,
         /**
          * @event edit
          * Fires when the 'edit' icon is pressed (add a listener to enable add button)
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
+        */
         'edit' : true,
         /**
          * @event remove
          * Fires when the remove value from the combobox array
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        */
         'remove' : true,
         /**
          * @event afterremove
          * Fires when the remove value from the combobox array
-            * @param {Roo.bootstrap.ComboBox} combo This combo box
-            */
+        * @param {Roo.bootstrap.ComboBox} combo This combo box
+        */
         'afterremove' : true,
         /**
          * @event specialfilter
@@ -337,7 +337,7 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
     animate : true,
     emptyResultText: 'Empty',
     triggerText : 'Select',
-    emptyTitle : false,
+    emptyTitle : '',
     
     // element that contains real text value.. (when hidden is used..)
     
@@ -368,10 +368,6 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
          */
         if(!this.tickable){
             cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
-            if(this.name == 'info_year_invest_id_display_name'){
-                Roo.log('cfg.................................................');
-                Roo.log(cfg);
-            }
             return cfg;
         }
         
@@ -597,38 +593,25 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
                         tag: 'label',
                         //cls : 'input-group-addon',
                         html : this.fieldLabel
-                        
                     },
-                    
                     combobox
-                    
                 ];
                 
                 if(this.indicatorpos == 'right'){
-                    
                     cfg.cn = [
                         {
                             tag: 'label',
                             //cls : 'input-group-addon',
-                            cn : [
-                                {
-                                    tag : 'span',
-                                    html : this.fieldLabel
-                                },
-                                {
-                                    tag : 'i',
-                                    cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
-                                    tooltip : 'This field is required'
-                                }
-                            ]
+                            html : this.fieldLabel
+                        },
+                        {
+                            tag : 'i',
+                            cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
+                            tooltip : 'This field is required'
                         },
-                        
-                        
-                        
                         combobox
-
                     ];
-                
+                    
                 }
 
         } else {
@@ -664,13 +647,15 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
             throw "can not find store for combo";
         }
         
+        this.indicator = this.indicatorEl();
+        
         this.store = Roo.factory(this.store, Roo.data);
+        this.store.parent = this;
         
         // if we are building from html. then this element is so complex, that we can not really
         // use the rendered HTML.
         // so we have to trash and replace the previous code.
         if (Roo.XComponent.build_from_html) {
-            
             // remove this element....
             var e = this.el.dom, k=0;
             while (e ) { e = e.previousSibling;  ++k;}
@@ -681,9 +666,6 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
             this.rendered = false;
             
             this.render(this.parent().getChildContainer(true), k);
-            
-            
-            
         }
         
         if(Roo.isIOS && this.useNativeIOS){
@@ -740,7 +722,6 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
         
         this.list.on('mouseover', this.onViewOver, this);
         this.list.on('mousemove', this.onViewMove, this);
-        
         this.list.on('scroll', this.onViewScroll, this);
         
         /*
@@ -798,7 +779,6 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
         this.view.on('click', this.onViewClick, this);
         
         
-        
         this.store.on('beforeload', this.onBeforeLoad, this);
         this.store.on('load', this.onLoad, this);
         this.store.on('loadexception', this.onLoadException, this);
@@ -1166,8 +1146,6 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
         
         if(this.store.getCount() > 0){
             
-            if(this.)
-            
             this.expand();
             this.restrictHeight();
             if(this.lastQuery == this.allQuery){
@@ -1381,7 +1359,12 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
         var close = this.closeTriggerEl();
         
         if(close){
-            (vv.length || vv * 1 > 0) ? close.show() : close.hide();
+            if(dv.length || vv * 1 > 0){
+                close.show() ;
+                this.blockFocus=true;
+            } else {
+                close.hide();
+            }             
         }
         
         if(this.hiddenField){
@@ -2007,7 +1990,7 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
                 {
                     tag: 'a',
                     href: '#',
-                    cls: 'roo-select2-search-choice-close',
+                    cls: 'roo-select2-search-choice-close fa fa-times',
                     tabindex: '-1'
                 }
             ]
@@ -2368,27 +2351,34 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
                 cfg.cn = [
                     {
                         tag: 'label',
+                        'for' :  id,
                         cls : 'control-label',
-                        html : this.fieldLabel,
                         cn : [
                             {
-                               tag : 'i',
-                               cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
-                               tooltip : 'This field is required'
+                                tag : 'span',
+                                html : this.fieldLabel
+                            },
+                            {
+                                tag : 'i',
+                                cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
+                                tooltip : 'This field is required'
                             }
                         ]
                     },
                     {
-                        cls : '', 
+                        cls : "",
                         cn: [
                             combobox
                         ]
                     }
+
                 ];
+                
+                labelCfg = cfg.cn[0];
+                contentCfg = cfg.cn[1];
             }
             
-            labelCfg = cfg.cn[0];
-            contentCfg = cfg.cn[2];
+           
             
             if(this.labelWidth > 12){
                 labelCfg.style = "width: " + this.labelWidth + 'px';
@@ -2577,9 +2567,10 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
         this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
         this.touchViewEl.show();
 
-        this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
-        this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
-                Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
+        this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
+        
+        //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
+        //        Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
 
         var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
 
@@ -2844,6 +2835,14 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
             
             var default_text = '-- SELECT --';
             
+            if(this.placeholder.length){
+                default_text = this.placeholder;
+            }
+            
+            if(this.emptyTitle.length){
+                default_text = ' - ' + this.emptyTitle + ' -';
+            }
+            
             var opt = this.inputEl().createChild({
                 tag: 'option',
                 value : 0,