We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31246 ☆ A M B ☆
    • 428 Posts
    Hi! In one of my projects, I did connect the combo boxes - country, region, city.
    The problem is, when rendering ComboBox, is not always displayed parameter displayField. Rather, instead of the name indicates id.
    Code example:
    ..........
    {
        xtype: 'westh-hotels-country'
        ,fieldLabel: _('westh.country')
        ,description: MODx.expandHelp ? '' : _('westh.desc_country')
        ,name: 'country'
        ,id: 'westh-country-category' + config.record.id
        ,anchor: '100%'
        ,value: config.record.con_id || 0
        ,allowBlank: false
        ,forceSelection: true
        ,listeners: {
                select: { fn:function(combo, value){
                    var acb = Ext.getCmp('westh-region-category' + config.record.id);
                    if (acb) {
                        var s = acb.store;
                        s.baseParams['country'] = value.id;
                        s.removeAll().load();
                        acb.clearValue();
                    }
                    var act = Ext.getCmp('westh-town-category' + config.record.id);
                    if (act) {
                        var t = act.store;
                        act.setDisabled(true);
                        act.clearValue();
                        }
                    }
                }
            }
        },{
        xtype: 'westh-hotels-region'
        ,fieldLabel: _('westh.region')
        ,description: MODx.expandHelp ? '' : _('westh.desc_region')
        ,name: 'region'
        ,id: 'westh-region-category' + config.record.id
        ,anchor: '100%'
        ,value: config.record.reg_id || 0
        ,allowBlank: false
        ,forceSelection: true
        ,listeners: {
                select: { fn:function(combo, value){
                    var acr = Ext.getCmp('westh-town-category' + config.record.id);
                    if (acr) {
                        acr.setDisabled(false);
                        var r = acr.store;
                        r.baseParams['region'] = value.id;
                        r.removeAll().load();
                        acr.clearValue();
                        }
                    }
                }
            }
        },{
        xtype: 'westh-hotels-town'
        ,fieldLabel: _('westh.town')
        ,description: MODx.expandHelp ? '' : _('westh.desc_town')
        ,name: 'sity'
        ,id: 'westh-town-category' + config.record.id
        ,anchor: '100%'
        ,value: config.record.town_id || 0
        ,allowBlank: false
        ,forceSelection: true
    }
    ........

    .......
    MODx.combo.country = function(config) {
    	config = config || {};
    	Ext.applyIf(config,{
    		name: 'country'
    		,hiddenName: 'country'
    		,displayField: 'title'
    		,valueField: 'id'
    		//,editable: true
    		,fields: ['title','id']
    		,pageSize: 20
    		//,value: config.record.con_id   || ''
    		,emptyText: _('westh.country.no')
    		,url: Westh.config.connectorUrl
    		,baseParams: {
    			action:  'mgr/country/getList'
                            ,'combo': true
    		}
    		
    	});
    	MODx.combo.country.superclass.constructor.call(this,config);
    };
    Ext.extend(MODx.combo.country,MODx.combo.ComboBox);
    Ext.reg('westh-hotels-country',MODx.combo.country);
    
    MODx.combo.region = function(config) {
    	config = config || {};
    	Ext.applyIf(config,{
    		name: 'region'
    		,hiddenName: 'region'
    		,displayField: 'title'
    		,valueField: 'id'
    		//,editable: true
    		,fields: ['title','id']
    		,pageSize: 20
    		//,value: config.record.con_id   || ''
    		,emptyText: _('westh.region.no')
    		,url: Westh.config.connectorUrl
    		,baseParams: {
    			action:  'mgr/region/getList'
                            ,'combo': true
    			,'country': country_id
    		}
    	});
    	MODx.combo.region.superclass.constructor.call(this,config);
    };
    Ext.extend(MODx.combo.region,MODx.combo.ComboBox);
    Ext.reg('westh-hotels-region',MODx.combo.region);
    
    MODx.combo.town = function(config) {
    	config = config || {};
    	Ext.applyIf(config,{
    		name: 'town'
    		,hiddenName: 'town'
    		,displayField: 'title'
    		,valueField: 'id'
    		//,editable: true
    		,fields: ['title','id']
    		,pageSize: 20
    		,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item">{title} ({id})</div></tpl>')
    		//,value: config.record.con_id   || ''
    		,emptyText: _('westh.town.no')
    		,url: Westh.config.connectorUrl
    		,baseParams: {
    			action:  'mgr/town/getList'
                            ,'combo': true
    			,'region': region_id
    		}
    	});
    	MODx.combo.town.superclass.constructor.call(this,config);
    };
    Ext.extend(MODx.combo.town,MODx.combo.ComboBox);
    Ext.reg('westh-hotels-town',MODx.combo.town);


    To understand it, watch the video
    How to make the display name instead of id?
    Thanks in advance! [ed. note: valikras last edited this post 14 years, 1 month ago.]
      Valentin Rasulov - Industrial design (Hobbies - Web Development)
      Development not standard projects on CMF MODx Revolution.
      Small sample of extensions
      • 4172
      • 5,888 Posts
      if you would use MIGXdb for your CMP you could use the dynamic dropdown - TVs for your cascading Comboboxes

      https://github.com/Bruno17/dddx
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Is dddx for front-end or Manager comboboxes?
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 31246 ☆ A M B ☆
          • 428 Posts
          @Bruno17 thanks for your answer.
          Perhaps I did not properly write, sorry for my English.
          I do not need TV. You can watch the video to understand. Does not always produce the correct parameter displayField in ComboBox. Tested Store - there is all the data.
            Valentin Rasulov - Industrial design (Hobbies - Web Development)
            Development not standard projects on CMF MODx Revolution.
            Small sample of extensions
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            MIGx is more than just a custom TV. It can also be used in the Manager in Custom Manager Pages. It simplifies creating CMP interfaces.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 4172
              • 5,888 Posts
              @Susan

              dddx is for comboboxes in the manager, can be used for Resources like normal listbox-TVs, but also for MIGX-db CMPs for custom-table-fields, if you need listboxes, which are depending on each other.

              some documentation, how to use it:
              https://github.com/Bruno17/dddx/tree/master/core/components/dddx/docs [ed. note: Bruno17 last edited this post 14 years, 1 month ago.]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 31246 ☆ A M B ☆
                • 428 Posts
                Mysticism!
                For example, I have the Processor classes getlist.class.php for combo.region
                <?php
                class WestRegionListProcessor extends modObjectGetListProcessor {
                    public $classKey = 'HotelsRegion';
                    public $languageTopics = array('westh:default');
                    public $defaultSortField = 'title';
                    public $defaultSortDirection = 'ASC';
                    public $objectType = 'westh.hotelsregion';
                    
                    public function prepareQueryBeforeCount(xPDOQuery $c) {        
                        $country = $this->getProperty('country',null);
                        if (empty($contry)) {
                            $c->where(array(
                                'country' => $country,
                            ));
                        }
                        $c->select('HotelsRegion.title,HotelsRegion.id');
                        return $c;
                    }       
                    
                    public function beforeIteration(array $list) {
                        if ($this->getProperty('combo',false)) {
                            $list[] = array(
                                'id' => '',
                                'title' => $this->modx->lexicon('westh.region_no'),
                            );
                        }
                        return $list;
                    }
                }
                return 'WestRegionListProcessor';

                I decided to try to use the spelling of the processor as before, to MODX 2.2.
                Rather, comment out getlist.class.php, and created getlist.php
                <?php
                $isLimit = !empty($scriptProperties['limit']);
                $start = $modx->getOption('start',$scriptProperties,0);
                $limit = $modx->getOption('limit',$scriptProperties,20);
                $sort = $modx->getOption('sort',$scriptProperties,'title');
                $dir = $modx->getOption('dir',$scriptProperties,'ASC');
                 
                /* build query */
                $c = $modx->newQuery('HotelsRegion');
                $count = $modx->getCount('HotelsRegion',$c);
                $c->sortby($sort,$dir);
                //if ($isLimit) $c->limit($limit,$start);
                $regions = $modx->getIterator('HotelsRegion', $c);
                 
                /* iterate */
                $list = array();
                foreach ($regions as $region) {
                    $regionArray = $region->toArray();
                    $list[]= $regionArray;
                }
                return $this->outputArray($list,$count);


                Hallelujah, everything was displayed correctly!
                Yet, I did not understand the reason for this behavior? [ed. note: valikras last edited this post 14 years, 1 month ago.]
                  Valentin Rasulov - Industrial design (Hobbies - Web Development)
                  Development not standard projects on CMF MODx Revolution.
                  Small sample of extensions