On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hello,

    I am trying to make my extras, all is fine except combo box... I want from combo box to show data from another table (names and id as identificator), but really don’t know how... I read some topics here, but it didn’t help me sad

    Here is my window + combo code

    Indications.combo.Type = function(config){
    	config = config || {};
    	
    	Ext.applyIf(config,{
    		hiddenName: 'id',
    		displayField: 'name',
    		valueField: 'id',
    		fields: ['id','name'],
    		url: '/assets/components/indications/connector-type.php',
    	});
    
    	Indications.combo.Type.superclass.constructor.call(this,config);
    };
    Ext.extend(Indications.combo.Type,MODx.combo.ComboBox);
    Ext.reg('indications-combo-type',Indications.combo.Type);
    
    Indications.window.CreateIndication = function(config) { 
        config = config || {}; 
        Ext.applyIf(config,{ 
            title: _('indications.indication_create') 
            ,url: Indications.config.connectorUrl 
            ,baseParams: { 
                action: 'mgr/indication/create'
            } 
            ,fields: [{ 
                xtype: 'textfield'
                ,fieldLabel: _('indications.name') 
                ,name: 'name'
                ,width: 300 
            },{ 
                xtype: 'textarea'
                ,fieldLabel: _('indications.application_count') 
                ,name: 'application_count'
                ,width: 300 
            },{ 
                xtype: 'textarea'
                ,fieldLabel: _('indications.application_length') 
                ,name: 'application_length'
                ,width: 300 
            },{ 
                xtype: 'textarea'
                ,fieldLabel: _('indications.using_addons') 
                ,name: 'using_addons'
                ,width: 300 
            },{ 
                xtype: 'textarea'
                ,fieldLabel: _('indications.application_docs') 
                ,name: 'application_docs'
                ,width: 300 
            },{ 
                xtype: 'textarea'
                ,fieldLabel: _('indications.acupressure_area') 
                ,name: 'acupressure_area'
                ,width: 300 
            },{ 
                xtype: 'textfield'
                ,fieldLabel: _('indications.link') 
                ,name: 'link'
                ,width: 300
            },{ 
                fieldLabel: _('indications.nameType') 
                ,name: 'indication_type'
                ,width: 300 
                ,xtype: 'indications-combo-type' 
            }] 
        }); 
        Indications.window.CreateIndication.superclass.constructor.call(this,config); 
    }; 
    Ext.extend(Indications.window.CreateIndication,MODx.Window); 
    Ext.reg('indications-window-indication-create',Indications.window.CreateIndication);


    Here is my connector (hope i do it well)
    <?php
    
    $c = $modx->newQuery('IndicationType'); 
    
    $indications = $modx->getIterator('IndicationType', $c); 
      
    /* iterate */
    $list = array(); 
    foreach ($indications as $indication) { 
        $indicationArray = $indication->toArray(); 
        $list[]= $indicationArray; 
    } 
    return $this->outputArray($list);


    Here is, how my tables look like
    <?xml version="1.0" encoding="UTF-8"?> 
    <model package="indications" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">    
        <object class="Indication" table="indications" extends="xPDOSimpleObject"> 
            <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/> 
            <field key="application_count" dbtype="varchar" precision="255" phptype="string" null="false" default=""/> 
            <field key="application_length" dbtype="varchar" precision="255" phptype="string" null="false" default=""/> 
            <field key="using_addons" dbtype="varchar" precision="255" phptype="string" null="true" default=""/> 
            <field key="application_docs" dbtype="varchar" precision="255" phptype="string" null="false" default=""/> 
            <field key="acupressure_area" dbtype="varchar" precision="255" phptype="string" null="false" default=""/> 
            <field key="indication_type" dbtype="int" precision="10" phptype="string" null="false" default=""/> 
            
            <field key="link" dbtype="int" phptype="integer" null="true" default=""/>
      
            <field key="createdon" dbtype="datetime" phptype="datetime" null="true"/> 
            <field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" /> 
            <field key="editedon" dbtype="datetime" phptype="datetime" null="true"/> 
            <field key="editedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" /> 
      
            <aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/> 
            <aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/> 
            
            <aggregate alias="Link" class="modResource" local="link" foreign="id" cardinality="one" owner="foreign"/> 
            <aggregate alias="IndicationType" class="IndicationType" local="indication_type" foreign="id" cardinality="one" owner="foreign"/>
        </object> 
        
        <object class="IndicationType" table="indication_types" extends="xPDOSimpleObject"> 
            <field key="name" dbtype="varchar" precision="64" phptype="string" null="false" default=""/> 
            <field key="css_name" dbtype="varchar" precision="64" phptype="string" null="false" default=""/>
     
            <field key="createdon" dbtype="datetime" phptype="datetime" null="true"/> 
            <field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" /> 
            <field key="editedon" dbtype="datetime" phptype="datetime" null="true"/> 
            <field key="editedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" /> 
      
            <aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/> 
            <aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>  
        </object> 
    </model>
      --
      John
      @theboxer
    • I think you did not specify your combo as an "xtype" in your window, e.g. refer back to name you used to register it in the Ext.reg call.

      For the posted code it should be something like:

      xtype: 'indications-combo-type'
      


      ...which refers back to combo class you defined at the beginning of the posted source.

      A working combo from my app is like below. It retrieves countries from the DB.

      Tariffs.combo.Countries = function(config){
      	config = config || {};
      	Ext.applyIf(config,{
      		hiddenName: 'country'
      		,name: 'country'
              ,width: 250
              ,listWidth: 300
      		,displayField: 'name'
      		,valueField: 'id'
      		,fields: ['id','name','code']
              ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name}</span>'
                  ,' ({code})</div></tpl>')
      		,url: Tariffs.config.connector_url
      		,emptyText: 'Select a country...'
      		,baseParams:{
      			action: 'mgr/booking/getcountrylist'
      		}
      	});
      	Tariffs.combo.Countries.superclass.constructor.call(this,config);
      };
      Ext.extend(Tariffs.combo.Countries,MODx.combo.ComboBox);
      Ext.reg('tariffs-combo-countries',Tariffs.combo.Countries);
      


      It’s usage in a window is:

      {
      			xtype: 'tariffs-combo-countries'
      			,fieldLabel: _('tariffs.booking_country')
      			,id: 'country_create'
      			,allowBlank: false
      		}
      


      Hope this helps...

      EDIT: It’s handy to keep reusable components like combo boxes in separate files. You can easily subclass them in their own source files and your main files don’t get cluttered with lots of class definitions. The general opinion on the Sencha forums is to put every class in its own file. There’s of course a trade-off with huge projects exploding into lots of files but it makes sense if you want to keep things organised.
        MODx Revolution / MAMP / OS X
      • Hello,
        thx for reply,

        I used my defined xtype in my window...
        ,{ 
                    fieldLabel: _('indications.nameType') 
                    ,name: 'indication_type'
                    ,width: 300 
                    ,xtype: 'indications-combo-type' 
                }]


        When I open the window, the combo box is there, but without values :-/

        How to store them in different files and where I should include them?
          --
          John
          @theboxer
        • Just navigate to this in your browser, ’/assets/components/indications/connector-type.php’ ie your connector, what do you get returned?
            Use MODx, or the cat gets it!
          • first I got:
            Notice: Undefined variable: modx in D:\Web\www\modx\assets\components\indications\connector-type.php on line 4 Fatal error: Call to a member function newQuery() on a non-object in D:\Web\www\modx\assets\components\indications\connector-type.php on line 4


            I added theese lines (they are in connector.php file)
            require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php'; 
            require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php'; 
            require_once MODX_CONNECTORS_PATH.'index.php';


            and now i am getting this error:
            Fatal error: Using $this when not in object context in D:\Web\www\modx\assets\components\indications\connector-type.php on line 16


            connector-type.php file:
            <?php                   
            require_once dirname(dirname(dirname(dirname(__FILE__)))).'/config.core.php'; 
            require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php'; 
            require_once MODX_CONNECTORS_PATH.'index.php';    
            
            $c = $modx->newQuery('IndicationType'); 
            
            $indications = $modx->getIterator('IndicationType', $c); 
              
            /* iterate */
            $list = array(); 
            foreach ($indications as $indication) { 
                $indicationArray = $indication->toArray(); 
                $list[]= $indicationArray; 
            } 
            return $this->outputArray($list);
              --
              John
              @theboxer
            • Ok, i solved this problem smiley look arond to others commponent and try something and its working smiley

              my combo box is look like:
              Indications.combo.Type = function(config){
              	config = config || {};
              	
              	Ext.applyIf(config,{
              		hiddenName: 'id',
              		displayField: 'name',
              		valueField: 'id',
              		fields: ['id','name'],
              		url: Indications.config.connectorUrl,
              		baseParams: { action: 'mgr/indication/getComboList' },
              	});
              
              	Indications.combo.Type.superclass.constructor.call(this,config);
              };
              Ext.extend(Indications.combo.Type,MODx.combo.ComboBox);
              Ext.reg('indications-combo-type',Indications.combo.Type);


              and i added processor file
              <?php                   
              
              $c = $modx->newQuery('IndicationType'); 
              
              $indications = $modx->getIterator('IndicationType', $c); 
                
              /* iterate */
              $list = array(); 
              foreach ($indications as $indication) { 
                  $indicationArray = $indication->toArray(); 
                  $list[]= $indicationArray; 
              } 
              return $this->outputArray($list);


              and delete that connector I posted here before smiley and it works fine...

              last task is to preselect first value... smiley anyone know how?
                --
                John
                @theboxer
              • try ’this.select.setValue(value);’ on your combo box, there’s also ’selectByValue(value, scrollIntoView) and select(index, scrollIntoView)’, have a look at the ExjS API reference.
                  Use MODx, or the cat gets it!
                • hmm... i tried this.select.setValue(value); but my form disappeared...

                  and second problem, in my grid is showed id... want name there :-/ when i double clicked combo appears well and works well, but in grid is id sad -- this sovled ,renderer: true smiley
                    --
                    John
                    @theboxer
                  • A disappearing form is generally a symptom of an error in your Javascript/ExtJS.

                    Do you use Chrome Javascript debugger or Firefox’s Firebug?

                    They should quickly point out the problem with your code.
                      MODx Revolution / MAMP / OS X
                    • opera dragonfly or firefox firebug, but the head problem is maybe in position of the line.. don’t know the right place for that...

                      and I got one more problem in SQL query...
                      want query like: "SELECT Indication.name, IndicationType.name FROM Indication LEFT JOIN IndicationType ON Indication.indication_type = IndicationType.id"

                      and parse it by the chunk, outpu should look like "Indication name - Indication type name"

                      my sql syntax in modx is:
                      $c = $modx->newQuery('Indication'); 
                      $c->select('Indication.*', 'IndicationType.name');
                      $c->leftJoin('IndicationType', 'IndicationType', 'Indication.indication_type = IndicationType.id');
                      $c->sortby($sort,$dir); 
                      $indications = $modx->getCollection('Indication',$c);
                      
                      foreach ($indications as $indication) { 
                          $indicationArray = $indication->toArray();
                          $output .= $indi->getChunk($tpl,$indicationArray); 
                         
                      }
                      
                      return $output; 


                      But I don’t know how to get the IndicationType.name ....

                      my chunk look like
                      <li><strong>[[+name]]</strong> - [[+IndicationType.name]]</li>


                      but it shows me only indication name, and name of type is empty :-/

                      (no error)
                        --
                        John
                        @theboxer