We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    Using a modx-combo-user with a big list of users doesn't render the username but it's ID instead. This happens if the user isn't within the first page of entries (default pageSize: 20).

    {
        xtype: MODx.config.publish_document ? 'modx-combo-user' : 'hidden'
        ,fieldLabel: _('resource_createdby')
        ,description: '<b>[[*createdby]]</b><br />'+_('resource_createdby_help')
        ,name: 'created_by'
        ,hiddenName: 'createdby'
        ,id: 'modx-resource-createdby'
        ,anchor: '100%'
        ,value: config.record.createdby || MODx.user.id
    }


    What am I doing wrong?

      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
      • 40045
      • 534 Posts
      This is from the core code at manager/assets/modext/widgets/core/modx.combo.js

      MODx.combo.User = function(config) {
          config = config || {};
          Ext.applyIf(config,{
              name: 'user'
              ,hiddenName: 'user'
              ,displayField: 'username'
              ,valueField: 'id'
              ,fields: ['username','id']
              ,pageSize: 20
              ,url: MODx.config.connector_url
              ,baseParams: {
                  action: 'security/user/getlist'
              }
              ,typeAhead: true
              ,editable: true
          });
          MODx.combo.User.superclass.constructor.call(this,config);
      };
      Ext.extend(MODx.combo.User,MODx.combo.ComboBox);
      Ext.reg('modx-combo-user',MODx.combo.User);
      


      first I'd try to remove your "value" config field, not sure if this is appropriate, but not entirely sure about it...does it work if you remove all of your custom config options?
        • 10378
        • 375 Posts
        I already tried to remove most options (except label and description) but this also didn't work.
        The value option is needed otherwise the field won't be filled with an initial value if loaded.

        I think the combo from core simply doesn't work as expected if there are more then 20 users in database and the desired user is not on the first page of the popup when the combo element is loading.
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/
          • 10378
          • 375 Posts
          This is also from the core code at manager/assets/modext/widgets/core/modx.combo.js and probably it hides the secret:
          (still trying to understand whats happening in this code part)

          /* store the original onLoad method to have acces to it in the override */
          var originalComboBoxOnLoad = Ext.form.ComboBox.prototype.onLoad;
          /* fixes combobox value loading issue */
          Ext.override(Ext.form.ComboBox, {
              loaded: false
              ,setValue: Ext.form.ComboBox.prototype.setValue.createSequence(function(v) {
                  var a = this.store.find(this.valueField, v);
                  if (v && v !== 0 && this.mode == 'remote' && a == -1 && !this.loaded) {
                      var p = {};
                      p[this.valueField] = v;
                      this.loaded = true;
                      this.store.load({
                          scope: this
                          ,params: p
                          ,callback: function() {
                              this.setValue(v);
                              this.collapse()
                          }
                      })
                  }
              })
              // this sets the width of combobox dropdown lists automatically to the width of the combobox element
              // and thus prevents the sometimes unnecessary wide dropdowns
              ,onLoad: function() {
                  var ret = originalComboBoxOnLoad.apply(this,arguments);
                  // true flag on getWidth() to ignore border and padding
                  var maxwidth = Math.max(this.minListWidth || 0, this.wrap.getWidth(true));
                  this.list.setWidth(maxwidth);
                  return ret;
              }
          });
          
            Freelancer @bitego http://www.bitego.com
            ---
            GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
            More infos here: http://www.bitego.com/extras/goodnews/
            • 40045
            • 534 Posts
            I only know what the second part (e.g. onLoad) does as it comes from me, the setValue stuff I don't know what exactly it does, guess your issue is more located in this direction right?
              • 10378
              • 375 Posts
              Quote from: exside at Aug 20, 2014, 11:20 AM
              I only know what the second part (e.g. onLoad) does as it comes from me, the setValue stuff I don't know what exactly it does, guess your issue is more located in this direction right?

              Yes I think so...
                Freelancer @bitego http://www.bitego.com
                ---
                GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                More infos here: http://www.bitego.com/extras/goodnews/
                • 10378
                • 375 Posts
                More than 2 years later and I still couldn't get this problem fixed:

                Using an extjs modx-combo-user with a big list of users (> pageSize) and trying to preselect a user, doesn't render the username but it's ID instead (if the preselected user isn't listed on first page of dropdown).

                Can someone help please?
                  Freelancer @bitego http://www.bitego.com
                  ---
                  GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                  More infos here: http://www.bitego.com/extras/goodnews/
                • It is a getlist processor issue.
                  • Try to add this code to the prepareQueryBeforeCount method in https://github.com/modxcms/revolution/blob/2.x/core/model/modx/processors/security/user/getlist.class.php#L35

                    $id = $this->getProperty('id');
                    if (!empty($id)) {
                        $c->where(array(
                            'id' => $id
                        ));
                    }

                      • 10378
                      • 375 Posts
                      Quote from: Jako at Jan 26, 2017, 09:51 PM
                      Try to add this code to the prepareQueryBeforeCount method in https://github.com/modxcms/revolution/blob/2.x/core/model/modx/processors/security/user/getlist.class.php#L35

                      $id = $this->getProperty('id');
                      if (!empty($id)) {
                          $c->where(array(
                              'id' => $id
                          ));
                      }


                      Bingo! This fixes the problem! Thanks alot @Jako!

                      So, I need to use my own getlist processor until the problem is fixed in MODX core.
                      As I don't have an actual setup to contribute directly to MODX - should I file a bug at GitHub or could someone create a quick PR?
                        Freelancer @bitego http://www.bitego.com
                        ---
                        GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                        More infos here: http://www.bitego.com/extras/goodnews/