Skip to content

Commit

Permalink
Attempt adding a multi checkbox field #143
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-H committed Oct 24, 2019
1 parent 9e6db4b commit fbee00d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
24 changes: 24 additions & 0 deletions assets/components/clientconfig/js/mgr/sections/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ Ext.extend(ClientConfig.page.Home,MODx.Component,{
field.value = 1;
field.checked = (value.value);
}
if (field.xtype === 'multi-checkbox') {
field.xtype = 'checkboxgroup';
field.columns = 1;
field.items = [{xtype: 'checkbox', boxLabel: 'foo', 'name': 'foo'}];

var options = value.options.split('||');
Ext.each(options, function(option, index) {
option = option.split('==');
if (option[1]) {
field.items.push({
boxLabel: option[0],
value: option[1],
name: field.name + '[]'
})
} else {
field.items.push({
boxLabel: option[0],
value: option[0],
name: field.name + '[]'
})
}
});
console.log(field);
}

if (field.xtype == 'datefield') {
field.format = MODx.config.manager_date_format;
Expand Down
1 change: 1 addition & 0 deletions assets/components/clientconfig/js/mgr/widgets/combos.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ClientConfig.combo.FieldTypes = function(config) {
['colorpickerfield', _('clientconfig.xtype.colorpalette')],
['email', _('clientconfig.xtype.email')],
['xcheckbox', _('clientconfig.xtype.xcheckbox')],
['multi-checkbox', _('clientconfig.xtype.multi-checkbox')],
['datefield', _('clientconfig.xtype.datefield')],
['timefield', _('clientconfig.xtype.timefield')],
['password', _('clientconfig.xtype.password')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ClientConfig.window.Setting = function(config) {
anchor: '100%',
listeners: {
select: {fn: function(field, record) {
if (record.data.xtype == 'modx-combo') {
if (['modx-combo', 'multi-checkbox'].indexOf(record.data.xtype) !== -1) {
Ext.getCmp(config.id + '-options').show();
Ext.getCmp(config.id + '-process_options').show();
} else {
Expand All @@ -97,7 +97,7 @@ ClientConfig.window.Setting = function(config) {
fieldLabel: _('clientconfig.options'),
description: _('clientconfig.options.desc'),
anchor: '100%',
hidden: (config.record && (config.record.xtype === 'modx-combo')) ? false : true
hidden: (config.record && (['modx-combo', 'multi-checkbox'].indexOf(config.record.xtype) !== -1)) ? false : true
},{
xtype: 'checkbox',
id: config.id + '-process_options',
Expand Down
2 changes: 1 addition & 1 deletion core/components/clientconfig/controllers/home.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function process(array $scriptProperties = array()) {
$googleFontsApiKey = $this->modx->getOption('clientconfig.google_fonts_api_key', null, '');
$sa['xtype'] = empty($googleFontsApiKey) ? 'textfield' : $sa['xtype'];
}
elseif ($sa['xtype'] === 'modx-combo' && $setting->get('process_options')) {
elseif ($setting->get('process_options') && in_array($sa['xtype'], ['modx-combo', 'multi-checkbox'], true)) {
$inputOpts = $setting->get('options');
$this->modx->getParser();
$this->modx->parser->processElementTags('', $inputOpts, true, true);
Expand Down
1 change: 1 addition & 0 deletions core/components/clientconfig/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@
$_lang['clientconfig.xtype.line'] = 'Line (divider)';
$_lang['clientconfig.xtype.code'] = 'Code (requires Ace editor installed)';
$_lang['clientconfig.xtype.email'] = 'Email';
$_lang['clientconfig.xtype.multi-checkbox'] = 'Multiple checkboxes';

0 comments on commit fbee00d

Please sign in to comment.