We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38181 ☆ A M B ☆
    • 26 Posts
    Hi - I have two combo boxes, sector and subsector. Sector is a table with 'id' and 'sector' as columns; subsector is 'id', 'sectorid' and 'subsector'.

    I have defined two combo boxes:

    SFProperties.combo.Sector = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            hiddenName: 'sector'
            ,displayField: 'sector'
            ,valueField: 'id'
            ,fields: ['id', 'sector']
            ,url: SFProperties.config.connectorUrl
            ,baseParams: { action: 'mgr/sfsector/getList'}
            ,editable: false
            ,lazyInit: false
        });
        SFProperties.combo.Sector.superclass.constructor.call(this,config);
    };
    Ext.extend(SFProperties.combo.Sector, MODx.combo.ComboBox);
    Ext.reg('combo-sector', SFProperties.combo.Sector);
    
    SFProperties.combo.Subsector = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            hiddenName: 'subsector'
            ,displayField: 'subsector'
            ,valueField: 'id'
            ,fields: ['id','sector','subsector']
            ,url: SFProperties.config.connectorUrl
            ,baseParams: { action: 'mgr/sfsubsector/getListfiltered' }
            ,editable: false
            ,lazyInit: false
        });
        SFProperties.combo.Subsector.superclass.constructor.call(this,config);
    };
    Ext.extend(SFProperties.combo.Subsector, MODx.combo.ComboBox);
    Ext.reg('combo-subsector', SFProperties.combo.Subsector);


    They are all working fine independently and getting data from the database.

    They are loaded using:

                   },{
                        xtype: 'combo-sector'
                        ,fieldLabel: _('sector')
                        ,name: 'sector'
                        ,listeners: {
                            'select': {fn: function(combo, value) { alert('Ahahah');
                            },scope: this}
                        }
                        ,width: 200
                    },{
                        xtype: 'combo-subsector'
                        ,fieldLabel: _('subsector')
                        ,name: 'subsector'
                        ,listeners: {
                            'beforeQuery': {fn: function(combo, value) {
                                alert('Ahahah - before query');
                            },scope: this}
                        }
                        ,width: 200
                    },{


    Now, I want the subsector list to be filtered, based on the sector of what has been selected in the first drop down - i.e. link the boxes.

    I am trying to do this in a beforeQuery listener (if that is right?) - but can't see how and what I have to do to link the two.

    Anyone help me out?

    Thanks
    Tim
      • 37286
      • 160 Posts
      Did you find a solution to this? I am trying to do something similar and this would be a big help.
        • 4172
        • 5,888 Posts
        I have created a dynamic-combobox-TV-extra which are configurable and can be linked to other ones of the same type (just define a parent-dynamic-TV-dropdown)
        I've used them also for custom-tables in MIGXdb - CMPs

        This Extra isn't on the Repo yet.
        Perhaps I can add it soon, if that would be a help.
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 37286
          • 160 Posts
          I haven't really worked with TV's much, but that would be helpful, or if you just have a piece of example code that would be a big help.
            • 4172
            • 5,888 Posts
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 37286
              • 160 Posts
              Thanks, I'm not strong with extjs yet, but I hope this will do it.
                • 38181 ☆ A M B ☆
                • 26 Posts
                Yes I seemed to solve the problem - extjs is not the easiest area to get to grips with but once you have grasped it it is well worth the effort. I have now developed over 50 CMP pages across a few client projects and the result of having everything seamlessly integrate in the manager is well worth it from an end user/usability perspective.

                So the solution I ended up with: first define the two combo boxes:

                SFProperties.combo.Sector = function(config) {
                    config = config || {};
                    Ext.applyIf(config,{
                        hiddenName: 'sector'
                        ,displayField: 'sector'
                        ,valueField: 'id'
                        ,fields: ['id', 'sector']
                        ,url: SFProperties.config.connectorUrl
                        ,baseParams: { action: 'mgr/sfsector/getList'}
                        ,editable: false
                        ,lazyInit: false
                    });
                    SFProperties.combo.Sector.superclass.constructor.call(this,config);
                };
                Ext.extend(SFProperties.combo.Sector, MODx.combo.ComboBox);
                Ext.reg('combo-sector', SFProperties.combo.Sector);
                
                SFProperties.combo.Subsector = function(config) {
                    config = config || {};
                    Ext.applyIf(config,{
                        hiddenName: 'subsector'
                        ,displayField: 'subsector'
                        ,valueField: 'id'
                        ,fields: ['id','sectorid','subsector']
                        ,url: SFProperties.config.connectorUrl
                        ,baseParams: { action: 'mgr/sfsubsector/getListfiltered' }
                        ,editable: false
                        ,lazyInit: false
                    });
                    SFProperties.combo.Subsector.superclass.constructor.call(this,config);
                };
                Ext.extend(SFProperties.combo.Subsector, MODx.combo.ComboBox);
                Ext.reg('combo-subsector', SFProperties.combo.Subsector);


                Then, when these are used within the ExtJS form definition, add a couple of in-line listeners:

                                },{
                                    xtype: 'combo-sector'
                                    ,fieldLabel: _('sector')
                                    ,name: 'sector'
                                    ,id: 'sector'
                                    ,listeners:
                                    {
                                         'select': { fn:function(combo, value)
                                         {
                                            var subsectorCmp = Ext.getCmp('subsector');
                                            subsectorCmp.setValue('');
                                            subsectorCmp.setDisabled(false);
                                            subsectorCmp.baseParams['sectorid'] = combo.getValue();
                                         }}
                                    }
                                    ,width: 200
                                },{
                                    xtype: 'combo-subsector'
                                    ,id: 'subsector'
                                    ,fieldLabel: _('subsector')
                                    ,name: 'subsector'
                                    ,disabled: true
                                    ,listeners:
                                    {
                                         'beforeQuery': { fn:function()
                                         {                            
                                            delete this.lastQuery;
                                         }}
                                    }
                                    ,width: 200
                


                Basically, on select of the sector, it gets a handle to the Ext component that you want to be linked. It sets a BaseParam that is used in the PHP processor file (in this case sectorid; then the 'beforeQuery' method on the second combo box first clears the current query, in effect forcing a refresh of the drop down list, by delete the cached lastQuery.

                Hope it helps.

                Tim
                  • 37286
                  • 160 Posts
                  This is awesome info, I think timothy's method is closer to the solution I am looking for right now, but I think bruno's will be a big help on a project I'm starting in a few weeks.

                  Thanks guys.