We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41002
    • 3 Posts
    Hello!
    I'm working over the CMP now. Working like in CMP development tutorial and rus translation modx.ws/razrabotka-dopolneniya-modx-revolution-2. Almost at last step i've got problem - can't place data from SuperBoxSelect to DB.

    Custom component looks like here:
    Repstat.combo.Work = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            xtype:'superboxselect'
            ,triggerAction: 'all'
            ,store: new Ext.data.ArrayStore({
                id: 0
                ,fields: ['work']
                ,data: [
                    ['repair']
                    ,['destruct']
                ]
            })
            ,displayField: 'work'
            ,valueField: 'work'
            ,mode: 'local'      
        });
        Repstat.combo.Work.superclass.constructor.call(this,config);
    };
    Ext.extend(Repstat.combo.Work,Ext.ux.form.SuperBoxSelect);
    Ext.reg('repstat-superCombo-work',Repstat.combo.Work);


    Call in Create Window:
    Repstat.window.CreateStatus = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            title: _('repstat.status_create')
            ,url: Repstat.config.connectorUrl
            ,baseParams: {
                action: 'mgr/repstat/create'
            }
            ,fields: [{
    
            ...
    
            },{
                xtype: 'repstat-superCombo-work'
               ,fieldLabel: _('repstat.work')
               ,name: 'work[]'
               ,hiddenName: 'work'
               ,anchor: '100%'
            },{
    
            ...
    
      }] 
        });
        Repstat.window.CreateStatus.superclass.constructor.call(this,config);
    };
    Ext.extend(Repstat.window.CreateStatus,MODx.Window);
    Ext.reg('repstat-window-status-create',Repstat.window.CreateStatus);
    
    


    Create processor:
    <?php
    class statusCreateProcessor extends modObjectCreateProcessor {
        public $classKey = 'status';
        public $languageTopics = array('repstat:default');
        public $objectType = 'repstat.status';
    
        public function beforeSave() {
    
            $imei = $this->getProperty('imei');
     
            if (empty($imei)) {
                $this->addFieldError('imei',$this->modx->lexicon('repstat.status_err_ns_imei'));
            } else if ($this->doesAlreadyExist(array('imei' => $imei))) {
                $this->addFieldError('imei',$this->modx->lexicon('repstat.status_err_ae'));
            }
            return parent::beforeSave();
        }
        
    }
    return 'statusCreateProcessor';
    


    I tried localize the problem next way: add this PHP code into the beforeSave() function
    $work[] = $this->getProperty('work');
            $this->addFieldError('work',$work[1]);

    This case i've got "Value of this field is wrong" <- translated from rus.
    If $work[0] than i get last added element.

    Where i may read more about processors working and where is my fault? How i can put some values from superselectbox into DB? I'm newbie in MODX(

    Thank you for respond and sorry for my bad english.
      • 4172
      • 5,888 Posts
      I think, you will get an array, and you need to convert it to a string, for example comma-seperated

      $work = $this->getProperty('work');
      if (is_array($work)){
          $this->setProperty('work',implode(',',$work));    
      }
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        That's a big problem with the processors. There appears to be no consistency in what data type they return, and it's very difficult to find out what data type any given processor returns.
          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
          • 41002
          • 3 Posts
          Quote from: Bruno17 at Mar 15, 2014, 02:19 AM
          I think, you will get an array, and you need to convert it to a string, for example comma-seperated

          $work = $this->getProperty('work');
          if (is_array($work)){
              $this->setProperty('work',implode(',',$work));    
          }

          It looks right - thx for PHP (i'm c#) smiley
          But...
          is_array($work)
          return that $work is not array coz
          $this->setProperty('work',implode(',',$work));
          is not performed. Probably problem hidden in the "hiddenName" or "name" in extjs. I rly can't understand what happend. May be we get array from superselectbox, get this data from $this, parse it by implode and put into the database. It's my picture of world) Thx for answer.
            • 4172
            • 5,888 Posts
            this one was working for me:

            https://forums.modx.com/thread/79754/cmp-superboxselector#dis-post-443020

            try:

            ,name: 'work'
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 41002
              • 3 Posts
              Quote from: Bruno17 at Mar 15, 2014, 03:45 PM
              this one was working for me:

              https://forums.modx.com/thread/79754/cmp-superboxselector#dis-post-443020

              try:

              ,name: 'work'

              Unfortunately doesn't affect. $work isn't array and contain last added to superboxselect element. Do u know where i may read about mechanism of transaction data from component kind combobox or superselectbox to
              $this->getProperty('work');
              . $this does mean the createWindow. But what is the 'work' in getPropery() method?

              I download SuperBoxSelect.js from Sencha and find here code below:
                  /**
                   * Returns a String value containing a concatenated list of item values. The list is concatenated with the {@link #Ext.ux.form.SuperBoxSelect-valueDelimiter}.
                   * @methodOf Ext.ux.form.SuperBoxSelect
                   * @name getValue
                   * @return {String} a String value containing a concatenated list of item values. 
                   */
                  getValue : function() {
                      var ret = [];
                      this.items.each(function(item){
                          ret.push(item.value);
                      });
                      return ret.join(this.valueDelimiter);
                  },


              Is this function getValue() provide data in to the 'work' in to the getProperty() method? In case of "yes" we must get comma delimeted items row. But we trying to get array of data. Do anyone have ideas?

              Bruno17 personal thanks to you.

              ADDED:
              How i undestand we work with object. In create processor we have next code:
               public $objectType = 'repstat.status';
              . It means we can get data from extjs to processor by this kind object.

              status.class.php contains code:
              <?php
              class status extends xPDOSimpleObject {}


              I think i must inspect xPDOSimpleObject. [ed. note: st.krezz last edited this post 12 years, 7 months ago.]