We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Can someone tell me how to save multiple checkboxes using EXT JS?

    I tried

    {
    xtype: 'checkbox',
    fieldLabel: ('horror'),
    name: 'genre',
    inputValue: 'horror',
    hideLabel: false,
    boxLabel: 'horror'
    },
    {
    xtype: 'checkbox',
    fieldLabel: ('action'),
    name: 'genre',
    inputValue: 'action',
    hideLabel: false,
    boxLabel: 'action'
    }
    


    This only saves action as it’s the last one to be sent so I thought to try this

    {
    xtype: 'checkbox',
    fieldLabel: ('horror'),
    name: 'genre[]',
    inputValue: 'horror',
    hideLabel: false,
    boxLabel: 'horror'
    },
    {
    xtype: 'checkbox',
    fieldLabel: ('action'),
    name: 'genre[]',
    inputValue: 'action',
    hideLabel: false,
    boxLabel: 'action'
    }
    


    In the DB it just says array.

    I am editing REV gallery to allow me to save multiple fields for creating an catalogue so I’ve edited the galalbum.map.inc.php file.

    'genre' => 
        array (
          'dbtype' => 'varchar',
          'precision' => '100',
          'phptype' => 'string',
          'null' => false,
          'default' => '',
          'index' => 'index',
        ),


    Should I change the phptype to array or what?

    Thanks

    EDIT ***

    OK I changed it to array and in the DB I have

    a:3:{i:0;s:2:"horror";i:1;s:3:"action"}


    How do I work with this when going to edit the page again? I have added ’genre’ => ’’, to the galalbum.map.inc.php file. The checkbox array is in the json feed but how do I get it to check the relevant boxes?

    "genre":"a:3:{i:0;s:2:\"horror\";i:1;s:3:\"action\";}"
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 25551 ☆ A M B ☆
      • 1,231 Posts
      I have changed my code to be like this.

      {
      					xtype: 'checkboxgroup',
      					fieldLabel:'genre',
      					columns:2,//showing two columns of checkboxes
      					items:[
      					{boxLabel: 'horror', name: 'platforms[horror]', inputValue: true}, 
      					{boxLabel: 'action', name: 'platforms[action]', inputValue: true},
      					{boxLabel: 'comedy', name: 'platforms[comedy]', inputValue: true}
      					]
      					}


      In the DB a single checkbox shows

      a:3:{s:2:"horror";s:4:"true";s:3:"action";s:4:"true";s:3:"comedy";s:4:"true";}


      I still cannot figure out how to work with this. How do you retrieve arrays like this in $xpdo_meta_map fields array so they are then checked or unchecked dependant on the value.
        Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
        AugmentBLU - MODX Partner

        BLUcart - MODX Revolution E-Commerce & Shopping Cart
        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Surely someone knows how to work with multiple checkboxes and EXTJS in the backend... or at least an idea how modx returns the data to the backend to populate them.
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 28215
          • 4,149 Posts
          Where are you using this? In a CMP, or a custom TV?
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 25551 ☆ A M B ☆
            • 1,231 Posts
            Thanks for the reply, I have edited the Gallery snippet you created. I am extending it to create a catalogue system based on the galleries. I added several fields, all are sent to the DB correctly and I can edit them fine. It’s just a checkboxgroup that I do not know how to get working correctly. I can get the info sent to the DB as you can see and it’s send back in the json feed to the manager when I go to edit again but I do not know how to make modx understand the array to check the checkboxes that had been selected on the save.

            I added this in the galalbum.map.inc.php file.

            'genre' => 
                array (
                  'dbtype' => 'varchar',
                  'precision' => '100',
                  'phptype' => 'array',
                  'null' => false,
                  'default' => '',
                  'index' => 'index',
                ),


            and this at the fields area at the top of the galalbum.map.inc.php file.

            'genre' => '',


            The array is sent correctly to the DB table. See the examples above.

            Hopefully you’re able to make out what I’m trying to do! grin
              Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
              AugmentBLU - MODX Partner

              BLUcart - MODX Revolution E-Commerce & Shopping Cart
              • 25551 ☆ A M B ☆
              • 1,231 Posts
              If I’m short on information I can try and provide more... I’m trying to understand how the new modx works so hopefully if I can continue altering the gallery script I will get an idea of how to build what I want.
                Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                AugmentBLU - MODX Partner

                BLUcart - MODX Revolution E-Commerce & Shopping Cart
                • 25551 ☆ A M B ☆
                • 1,231 Posts
                I can’t solve this at all, is there modx documentation that will help specifically with how the new modx deals with feeds in the backend? This one issue is holding me up and it’s so frustrating! >:(

                Thanks!
                  Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                  AugmentBLU - MODX Partner

                  BLUcart - MODX Revolution E-Commerce & Shopping Cart
                  • 28215
                  • 4,149 Posts
                  It’s really hard to help you without seeing more of the code you’re using to implement this. Please specify exactly how this code is being used, and provide any related code that might be causing the problem. Also, state what values you’re getting and what you expect to be getting.

                  Secondly, what version of Revo.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 25551 ☆ A M B ☆
                    • 1,231 Posts
                    OK sorry, here’s each file I have edited... might not be pretty but I have tried my best to understand the new way of working.

                    I am using MODx Revolution 2.0.4-pl2 and your Gallery snippet 1.0.1-rc2.

                    I have highlighted my editions with a line of ***.

                    FILE - assets/components/gallery/js/mgr/widgets/album

                    GAL.panel.Album = function(config) {
                        config = config || {};
                            
                        Ext.apply(config,{
                            id: 'gal-panel-album'
                            ,url: GAL.config.connector_url
                            ,baseParams: {}
                            ,border: false
                            ,baseCls: 'modx-formpanel'
                            ,items: [{
                                html: '<h2>'+_('gallery.album')+'</h2>'
                                ,border: false
                                ,id: 'gal-album-header'
                                ,cls: 'modx-page-header'
                            },{
                                xtype: 'modx-tabs'
                                ,bodyStyle: 'padding: 10px'
                                ,defaults: { border: false ,autoHeight: true }
                                ,border: true
                                ,activeItem: 0
                                ,hideMode: 'offsets'
                                ,items: [{
                                    title: _('general_information')
                                    ,layout: 'form'
                                    ,items: [{                    
                                        xtype: 'statictextfield'
                                        ,fieldLabel: _('id')
                                        ,name: 'id'
                                        ,submitValue: true
                                    },{
                                        xtype: 'textfield'
                                        ,fieldLabel: _('name')
                                        ,name: 'name'
                                        ,width: 250
                                        ,allowBlank: false  
                                    },
                    *************************
                    				{
                                        xtype: 'textfield'
                                        ,fieldLabel: ('Movie Director')
                                        ,name: 'director'
                                        ,width: 250
                                        ,allowBlank: false  
                                    }
                    				,{
                    					xtype: 'checkboxgroup',
                    					fieldLabel:'genre',
                    					columns:2,//showing two columns of checkboxes
                    					items:[
                    					{boxLabel: 'action', name: 'genre[action]', inputValue: true}, 
                    					{boxLabel: 'horror', name: 'genre[horror]', inputValue: true},
                    					{boxLabel: 'comedy', name: 'genre[comedy]', inputValue: true}
                    					]
                    					},
                    *************************
                    					
                    		{
                                        xtype: 'textfield'
                                        ,fieldLabel: ('Minimum Requirements')
                                        ,name: 'req'
                                        ,width: 250
                                        ,allowBlank: false  
                                    }				
                    							
                    				,{
                                            xtype: 'datefield',
                                            name: 'releasedate',
                                            fieldLabel: 'Release date',
                                            allowBlank: false,  
                    						width: 250,
                                          
                                    }
                    				,{
                                        xtype: 'textarea'
                                        ,fieldLabel: _('description')
                                        ,name: 'description'
                                        ,width: 400
                                    },{
                                        xtype: 'checkbox'
                                        ,fieldLabel: _('gallery.active')
                                        ,description: _('gallery.active_desc')
                                        ,name: 'active'
                                        ,inputValue: true
                                    },{
                                        xtype: 'checkbox'
                                        ,fieldLabel: _('gallery.prominent')
                                        ,description: _('gallery.prominent_desc')
                                        ,name: 'prominent'
                                        ,inputValue: true
                                    }
                    				,{
                                        html: '<hr />',border: false
                    				}
                    				,{
                                        xtype: 'gal-panel-album-items'
                                        ,cls: 'modx-pb-view-ct'
                                        ,album: config.album
                                    }]
                                }/*,{
                                    title: 'Context Access'
                                    ,layout: 'form'
                                    ,items: [{
                                        html: '<p>Manage the Contexts that have access to this album.</p><br />'
                                        ,border: false
                                    }]
                                }*/]
                            }]
                            ,listeners: {
                                'setup': {fn:this.setup,scope:this}
                                ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
                                ,'success': {fn:this.success,scope:this}
                            }
                        });
                        GAL.panel.Album.superclass.constructor.call(this,config);
                    };
                    Ext.extend(GAL.panel.Album,MODx.FormPanel,{
                        setup: function() {
                            if (!this.config.album) return;
                            MODx.Ajax.request({
                                url: this.config.url
                                ,params: {
                                    action: 'mgr/album/get'
                                    ,id: this.config.album
                                }
                                ,listeners: {
                                    'success': {fn:function(r) {
                                        this.getForm().setValues(r.object);
                    
                                        Ext.getCmp('gal-album-header').getEl().update('<h2>'+_('gallery.album')+': '+r.object.name+'</h2>');
                                    },scope:this}
                                }
                            });
                        }
                        ,beforeSubmit: function(o) {
                            Ext.apply(o.form.baseParams,{
                            });
                        }
                        ,success: function(o) {
                            Ext.getCmp('dis-btn-save').setDisabled(false);
                        }
                    });
                    Ext.reg('gal-panel-album',GAL.panel.Album);
                    
                    GAL.panel.AlbumItems = function(config) {
                        config = config || {};
                        
                        this.view = MODx.load({
                            id: 'gal-album-items-view'
                            ,xtype: 'gal-view-album-items'
                            ,onSelect: {fn:function() { }, scope: this}
                            ,containerScroll: true
                            ,ident: this.ident
                            ,cls: 'gal-view-album-items'
                            ,album: config.album
                            ,inPanel: true
                            ,style: 'overflow: auto;'
                        });
                        this.view.pagingBar = new Ext.PagingToolbar({
                            pageSize: 24
                            ,store: this.view.store
                            ,displayInfo: true
                            ,autoLoad: true
                        });
                        var dv = this.view;
                        
                        
                        dv.on('render', function() {
                            dv.dragZone = new MODx.DataView.dragZone(dv);
                            dv.dropZone = new MODx.DataView.dropZone(dv);
                        });
                        
                        Ext.applyIf(config,{
                            id: 'gal-panel-album-items'
                            ,cls: 'browser-win'
                            ,layout: 'column'
                            ,minWidth: 500
                            ,minHeight: 350
                            ,width: '90%'
                            ,autoHeight: true
                            ,modal: false
                            ,closeAction: 'hide'
                            ,border: false
                            ,autoScroll: true
                            ,items: [{
                                id: 'gal-album-items-ct'
                                ,cls: 'browser-view'
                                ,region: 'center'
                                ,width: '80%'
                                ,height: 450
                                ,autoScroll: true
                                ,border: false
                                ,items: [{
                                    xtype: 'toolbar'
                                    ,items: [{
                                        xtype: 'button'
                                        ,text: _('gallery.item_upload')
                                        ,handler: this.uploadItem
                                        ,scope: this
                                    },'-',{
                                        xtype: 'button'
                                        ,text: _('gallery.batch_upload')
                                        ,handler: this.batchUpload
                                        ,scope: this
                                    }]
                                },this.view]
                                ,bbar: [this.view.pagingBar]
                            },{
                                html: ''
                                ,id: 'gal-album-items-detail'
                                ,region: 'east'
                                ,split: true
                                ,autoScroll: true
                                ,width: '20%'
                                ,minWidth: 150
                                ,maxWidth: 250
                                ,height: 450
                                ,border: false
                            }]
                        });
                        GAL.panel.AlbumItems.superclass.constructor.call(this,config);
                        
                    };
                    Ext.extend(GAL.panel.AlbumItems,MODx.Panel,{
                        windows: {}
                    
                        ,handleSort: function(o) {
                            var s = this.view.store;
                            console.log(o);
                            return;
                            var origRec = s.getAt(o.sourceId);
                            var lastRec = s.getAt(o.targetId);
                    
                            MODx.Ajax.request({
                                url: this.config.url
                                ,params: {
                                    action: 'item/sort'
                                    ,album: this.config.album
                                    ,source: o.sourceIndex
                                    ,target: o.targetIndex
                                }
                            });
                        }
                        
                        ,uploadItem: function(btn,e) {
                            var r = {
                                album: this.config.album
                                ,active: true
                            };
                            if (!this.windows.uploadItem) {
                                this.windows.uploadItem = MODx.load({
                                    xtype: 'gal-window-item-upload'
                                    ,listeners: {
                                        'success': {fn:function() { this.view.run(); },scope:this}
                                    }
                                });
                            }
                            this.windows.uploadItem.fp.getForm().reset();
                            this.windows.uploadItem.setValues(r);
                            this.windows.uploadItem.show(e.target);
                        }
                    
                        ,batchUpload: function(btn,e) {
                            var r = {
                                album: this.config.album
                                ,active: true
                            };
                            if (!this.windows.batchUpload) {
                                this.windows.batchUpload = MODx.load({
                                    xtype: 'gal-window-batch-upload'
                                    ,listeners: {
                                        'success': {fn:function() { this.view.run(); },scope:this}
                                    }
                                });
                            } else {
                                this.windows.batchUpload.fp.getForm().reset();
                            }
                            this.windows.batchUpload.setValues(r);
                            this.windows.batchUpload.show(e.target);
                        }
                    });
                    Ext.reg('gal-panel-album-items',GAL.panel.AlbumItems);
                    
                    
                    
                    GAL.window.UploadItem = function(config) {
                        config = config || {};
                        this.ident = config.ident || 'gupit'+Ext.id();
                        Ext.applyIf(config,{
                            title: _('gallery.item_upload')
                            ,id: this.ident
                            ,height: 150
                            ,width: 475
                            ,url: GAL.config.connector_url
                            ,action: 'mgr/item/upload'
                            ,fileUpload: true
                            ,fields: [{
                                xtype: 'hidden'
                                ,name: 'album'
                            },{
                                xtype: 'textfield'
                                ,inputType: 'file'
                                ,fieldLabel: _('gallery.file')
                                ,name: 'file'
                                ,id: 'gal-'+this.ident+'-file'
                            },{
                                xtype: 'textfield'
                                ,fieldLabel: _('name')
                                ,name: 'name'
                                ,id: 'gal-'+this.ident+'-name'
                                ,width: 300
                            }
                    		,{
                    	xtype: 'textarea'
                    	,fieldLabel: _('description')
                    	,name: 'description'
                    	,id: 'gal-'+this.ident+'-description'
                    	,width: 300
                            },{
                                xtype: 'checkbox'
                                ,fieldLabel: _('gallery.active')
                                ,name: 'active'
                                ,description: ''
                                ,id: 'gal-'+this.ident+'-active'
                                ,checked: true
                                ,inputValue: 1
                            },{
                                xtype: 'textfield'
                                ,fieldLabel: _('gallery.tags')
                                ,description: _('gallery.comma_separated_list')
                                ,name: 'tags'
                                ,id: 'gal-'+this.ident+'-tags'
                            }]
                        });
                        GAL.window.UploadItem.superclass.constructor.call(this,config);
                    };
                    Ext.extend(GAL.window.UploadItem,MODx.Window);
                    Ext.reg('gal-window-item-upload',GAL.window.UploadItem);
                    
                    GAL.window.BatchUpload = function(config) {
                        config = config || {};
                        this.ident = config.ident || 'gupbu'+Ext.id();
                        Ext.applyIf(config,{
                            title: _('gallery.batch_upload')
                            ,id: this.ident
                            ,height: 150
                            ,width: 475
                            ,url: GAL.config.connector_url
                            ,action: 'mgr/item/batchupload'
                            ,fileUpload: true
                            ,fields: [{
                                xtype: 'hidden'
                                ,name: 'album'
                            },{
                                html: _('gallery.batch_upload_intro')
                                ,border: false
                            },MODx.PanelSpacer,{
                                xtype: 'textfield'
                                ,fieldLabel: _('gallery.directory')
                                ,name: 'directory'
                                ,id: 'gal-'+this.ident+'-directory'
                                ,width: 300
                                ,value: MODx.config['gallery.default_batch_upload_path'] || '{assets_path}images/'
                            },{
                                xtype: 'checkbox'
                                ,fieldLabel: _('gallery.active')
                                ,name: 'active'
                                ,description: ''
                                ,id: 'gal-'+this.ident+'-active'
                                ,checked: true
                                ,inputValue: 1
                            },{
                                xtype: 'textfield'
                                ,fieldLabel: _('gallery.tags')
                                ,description: _('gallery.batch_upload_tags')
                                ,name: 'tags'
                                ,id: 'gal-'+this.ident+'-tags'
                                ,width: 300
                            }]
                        });
                        GAL.window.BatchUpload.superclass.constructor.call(this,config);
                    };
                    Ext.extend(GAL.window.BatchUpload,MODx.Window);
                    Ext.reg('gal-window-batch-upload',GAL.window.BatchUpload);
                    



                    FILE - core/components/gallery/model/gallery/mysql/galalbum.map.inc.php

                    <?php
                    /**
                     * @package gallery
                     */
                    $xpdo_meta_map['galAlbum']= array (
                      'package' => 'gallery',
                      'table' => 'gallery_albums',
                      'fields' => 
                      array (
                        'parent' => 0,
                        'name' => '',
                        'description' => '',
                        'createdon' => NULL,
                        'createdby' => 0,
                        'rank' => 0,
                        'active' => 0,
                        'prominent' => 0,
                        'watermark' => '',
                    *************************
                    'director' => '',
                    'genre' => '',
                    *************************
                      ),
                      'fieldMeta' => 
                      array (
                        'parent' => 
                        array (
                          'dbtype' => 'int',
                          'precision' => '10',
                          'phptype' => 'integer',
                          'attributes' => 'unsigned',
                          'null' => false,
                          'default' => 0,
                          'index' => 'index',
                        ),
                        'name' => 
                        array (
                          'dbtype' => 'varchar',
                          'precision' => '255',
                          'phptype' => 'string',
                          'null' => false,
                          'default' => '',
                          'index' => 'index',
                        ),
                    *************************
                        'director' => 
                        array (
                          'dbtype' => 'varchar',
                          'precision' => '255',
                          'phptype' => 'string',
                          'null' => false,
                          'default' => '',
                          'index' => 'index',
                        ),
                    
                    'genre' => 
                        array (
                          'dbtype' => 'varchar',
                          'precision' => '100',
                          'phptype' => 'array',
                          'null' => false,
                          'default' => '',
                          'index' => 'index',
                        ),
                    *************************
                        'description' => 
                        array (
                          'dbtype' => 'text',
                          'phptype' => 'string',
                          'null' => false,
                          'default' => '',
                        ),
                        'createdon' => 
                        array (
                          'dbtype' => 'datetime',
                          'phptype' => 'datetime',
                          'null' => true,
                        ),
                        'createdby' => 
                        array (
                          'dbtype' => 'int',
                          'precision' => '10',
                          'phptype' => 'integer',
                          'attributes' => 'unsigned',
                          'null' => false,
                          'default' => 0,
                          'index' => 'index',
                        ),
                        'rank' => 
                        array (
                          'dbtype' => 'int',
                          'precision' => '10',
                          'phptype' => 'integer',
                          'attributes' => 'unsigned',
                          'null' => false,
                          'default' => 0,
                        ),
                        'active' => 
                        array (
                          'dbtype' => 'tinyint',
                          'precision' => '1',
                          'phptype' => 'integer',
                          'attributes' => 'unsigned',
                          'null' => false,
                          'default' => 0,
                        ),
                    		
                        'prominent' => 
                        array (
                          'dbtype' => 'tinyint',
                          'precision' => '1',
                          'phptype' => 'integer',
                          'attributes' => 'unsigned',
                          'null' => false,
                          'default' => 0,
                        ),
                        'watermark' => 
                        array (
                          'dbtype' => 'varchar',
                          'precision' => '255',
                          'phptype' => 'string',
                          'null' => false,
                          'default' => '',
                        ),
                      ),
                      'aggregates' => 
                      array (
                        'Parent' => 
                        array (
                          'class' => 'galAlbum',
                          'local' => 'parent',
                          'foreign' => 'id',
                          'cardinality' => 'one',
                          'owner' => 'foreign',
                        ),
                        'CreatedBy' => 
                        array (
                          'class' => 'modUser',
                          'local' => 'createdby',
                          'foreign' => 'id',
                          'cardinality' => 'one',
                          'owner' => 'foreign',
                        ),
                      ),
                      'composites' => 
                      array (
                        'AlbumItems' => 
                        array (
                          'class' => 'galAlbumItem',
                          'local' => 'id',
                          'foreign' => 'album',
                          'cardinality' => 'many',
                          'owner' => 'local',
                        ),
                        'Contexts' => 
                        array (
                          'class' => 'galAlbumContext',
                          'local' => 'id',
                          'foreign' => 'album',
                          'cardinality' => 'many',
                          'owner' => 'local',
                        ),
                        'Children' => 
                        array (
                          'class' => 'galAlbum',
                          'local' => 'id',
                          'foreign' => 'parent',
                          'cardinality' => 'many',
                          'owner' => 'local',
                        ),
                      ),
                    );
                    


                    I created the new fields in the database, everything is being sent correctly. If I create a new gallery and I am in the gallery edit area I see the new options. If I fill them out this works as expected. The checkboxgroup is being sent as an array, the database shows this info if 2 checkboxes are clicked like this...

                    a:2:{s:2:"horror";s:4:"true";s:3:"action";s:4:"true";}"


                    The feed in the connector.php displayed in Firebug shows

                    "genre":"a:2:{s:2:\"horror\";s:4:\"true\";s:3:\"action\";s:4:\"true\";}",


                    After the new selections are sent and saved the feed back to the gallery does have the checkbox array but what I do not know how to do is say checkbox X and Y are present in the database so make them checked on the gallery edit page. The reason I am using checkboxgroups is to keep all related information together so it’s easily searched, also this is a very basic example of what I am trying to do and I want to keep all related data together in the database.

                    So basically I have everything working, I just don’t know how to say to the gallery edit page that this checkbox of checkboxgroup genre has been clicked according to the database so display it as checked.

                    I hope this is enough information to help.
                      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                      AugmentBLU - MODX Partner

                      BLUcart - MODX Revolution E-Commerce & Shopping Cart
                      • 25551 ☆ A M B ☆
                      • 1,231 Posts
                      Am I still lacking some details for anyone to help out with this issue? Please let me know and I’ll post it, I’m hoping to get on with working further on my idea but it’s these checkboxes that are holding me up grin

                      Thanks!
                        Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                        AugmentBLU - MODX Partner

                        BLUcart - MODX Revolution E-Commerce & Shopping Cart