We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8274 ☆ A M B ☆
    • 222 Posts
    I have created a CMP that lists products from a custom db table in an ExtJS grid. The product info can be updated through an UpdateWindow.

    There are four check boxes to help categorize the product. These are not mandatory, but if one has been checked (value of 1 saved to the record's field), I need to have it display on the next load.

    Here's my issue: on the first load of the grid, ANY update window launched will not "check" the boxes as appropriate for the targeted product. All other textfields and comboboxes are filled properly, just not the check boxes.

    If the window is closed (save or cancel, or even just closing the window), and then reopened, it populates fine. OR if the grid is refreshed (using the bottom bar refresh button), the checkbox works fine the first time.

    So I assume this is something to do with the loading of the products data store, but I can't figure out where to do this.

    Db field is a tinyint format (i save either a 1 or 0 depending on whether the the box is checked or not). I am using the modx-checkbox datatype so that a 0 is saved if the box is unchecked.

    This is in Revo 2.2.5.

    link to my code is on gist:
    https://gist.github.com/8b68f528e761bc12a133

    what little step am I missing on this?

    This question has been answered by dvstudiosinc. See the first response.

      • 18373 ☆ A M B ☆
      • 3,141 Posts
          ,updateProduct: function(btn,e) {
              if (!this.updateProductWindow) {
                  this.updateProductWindow = MODx.load({
                      xtype: 'products-window-product-update'
                      ,record: this.menu.record
                      ,listeners: {
                          'success': {fn:this.refresh,scope:this}
                      }
                  });
              }
              this.updateProductWindow.reset();
              this.updateProductWindow.setValues(this.menu.record);
              this.updateProductWindow.show(e.target);
          }


      Personally I don't like this type of reuse because of data lingering around, but it can help keep the DOM in control if you're expecting to be opening up a ton of windows. Still I tend to use something like this instead...

          ,updateProduct: function(btn,e) {
               var win = MODx.load({
                  xtype: 'products-window-product-update'
                  ,record: this.menu.record
                  ,listeners: {
                      'success': {fn:this.refresh,scope:this}
                 }
              });
              win.setValues(this.menu.record);
              win.show(e.target);
          }


      Instead of your inputType: '1' in the checkbox definitions, I prefer changing my data (in this case, the fields definition of the grid) to interpret it as a true or false already.
      ,fields: ['id',..., {name: 'audience_asphalt', type: 'bool'}, {name: 'audience_engineers', type: 'bool'}, 'audience_maintenance', 'audience_contracting']

      which means it also understands a false value.

      Related to that, also have a look at what sort of data your getlist processor is returning (which will most likely depend on the "phptype" of your fields' schema definition). That all needs to be in sync, and I prefer it returning a boolean which is quite universal. This may actually be the issue you are seeing, where it has issues interpreting the actual value.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • discuss.answer
        • 8274 ☆ A M B ☆
        • 222 Posts
        This issue seems to be directly related to the checkboxes being included in a checkbox group element. Not sure why the checkbox group won't load the values up on FIRST instantiation of the update window... something to research later (my guess it is an odd pathing issue, or reference issue).

        I haven't dealt with checkbox groups before, so this is being shelved for a later time.

        Thanks for you help, Mark.
          • 39465
          • 14 Posts
          Long live the Mark Hamstra smiley The new way of update function, fixed my bug with checbox aswell. Thanks alot