Skip to content

Commit e3b6da2

Browse files
authored
Add checkbox TV input option to display inputs as switches/toggles (#16631)
### Why is it needed? For some TVs, the switch style may be more appropriate to the content being collected. This update allows users to choose how to display their checkbox TVs. ### How to test Create a new checkbox TV (or use an existing one) and verify that changing the "Display as Switch" option has the expected effect when the TV is displayed in the Resource editing form. ### Related issue(s)/PR(s) Alternate solution to PR #16623
1 parent 9edf1ba commit e3b6da2

File tree

3 files changed

+57
-23
lines changed

3 files changed

+57
-23
lines changed

core/lexicon/en/tv_widget.inc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
$_lang['checkbox'] = 'Check Box';
2020
$_lang['checkbox_columns'] = 'Columns';
2121
$_lang['checkbox_columns_desc'] = 'The number of columns the checkboxes are displayed in.';
22+
$_lang['checkbox_display_switch'] = 'Display as Switch';
23+
$_lang['checkbox_display_switch_desc'] = 'When set to “Yes,” this TV’s inputs will be rendered in the Resource editing form as switches (toggles) instead of checked boxes. (Default: “No”)';
2224
$_lang['class'] = 'Class';
2325
$_lang['classes'] = 'Class(es)';
2426
$_lang['combo_allowaddnewdata'] = 'Allow Add New Items';

core/src/Revolution/Processors/Element/TemplateVar/Configs/mgr/inputproperties/checkbox.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,29 @@
1515

1616
# Set values
1717
$columns = !empty($params['columns']) ? $params['columns'] : 1 ;
18+
$displayAsSwitch = $params['displayAsSwitch'] === 'true' || $params['displayAsSwitch'] == 1 ? 'true' : 'false' ;
1819

1920
# Set help descriptions
2021
$descKeys = [
2122
'required_desc',
22-
'checkbox_columns_desc'
23+
'checkbox_columns_desc',
24+
'checkbox_display_switch_desc'
2325
];
2426
$this->setHelpContent($descKeys, $expandHelp);
2527

2628
$optsJS = <<<OPTSJS
2729
[
2830
{
2931
defaults: {
32+
xtype: 'panel',
3033
layout: 'form',
34+
labelAlign: 'top',
35+
autoHeight: true,
3136
labelSeparator: ''
3237
},
3338
items: [
3439
{
35-
xtype: 'panel',
36-
columnWidth: 1,
37-
autoHeight: true,
38-
labelAlign: 'top',
40+
columnWidth: 0.34,
3941
defaults: {
4042
anchor: '100%',
4143
msgTarget: 'under'
@@ -53,7 +55,36 @@
5355
forId: 'inopt_allowBlank{$tvId}',
5456
html: {$this->helpContent['required_desc']},
5557
cls: 'desc-under'
58+
}]
59+
},
60+
{
61+
columnWidth: 0.33,
62+
defaults: {
63+
anchor: '100%',
64+
msgTarget: 'under'
65+
},
66+
items: [{
67+
xtype: 'combo-boolean',
68+
fieldLabel: _('checkbox_display_switch'),
69+
description: {$this->helpContent['eh_checkbox_display_switch_desc']},
70+
name: 'inopt_displayAsSwitch',
71+
hiddenName: 'inopt_displayAsSwitch',
72+
id: 'inopt_displayAsSwitch{$tvId}',
73+
value: {$displayAsSwitch}
5674
},{
75+
xtype: '{$helpXtype}',
76+
forId: 'inopt_displayAsSwitch{$tvId}',
77+
html: {$this->helpContent['checkbox_display_switch_desc']},
78+
cls: 'desc-under'
79+
}]
80+
},
81+
{
82+
columnWidth: 0.33,
83+
defaults: {
84+
anchor: '100%',
85+
msgTarget: 'under'
86+
},
87+
items: [{
5788
xtype: 'numberfield',
5889
fieldLabel: _('checkbox_columns'),
5990
description: {$this->helpContent['eh_checkbox_columns_desc']},

manager/templates/default/element/tv/renders/input/checkbox.tpl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
Ext.onReady(function() {
77
const fld = MODx.load({
88
{/literal}
9-
xtype: 'checkboxgroup'
10-
,id: 'tv{$tv->id}'
11-
,itemId: 'tv{$tv->id}'
12-
,vertical: true
13-
,columns: {if $params.columns|default}{$params.columns|default}{else}1{/if}
14-
,renderTo: 'tv{$tv->id}-cb'
15-
,name: 'tv-{$tv->id}'
16-
,width: '99%'
17-
,allowBlank: {if $params.allowBlank == 1 || $params.allowBlank == 'true'}true{else}false{/if}
18-
,hideMode: 'offsets'
19-
,msgTarget: 'under'
20-
,items: [{foreach from=$opts item=item key=k name=cbs}
9+
xtype: 'checkboxgroup',
10+
id: 'tv{$tv->id}',
11+
itemId: 'tv{$tv->id}',
12+
vertical: true,
13+
columns: {if $params.columns|default}{$params.columns|default}{else}1{/if},
14+
renderTo: 'tv{$tv->id}-cb',
15+
name: 'tv-{$tv->id}',
16+
width: '99%',
17+
allowBlank: {if $params.allowBlank == 1 || $params.allowBlank == 'true'}true{else}false{/if},
18+
hideMode: 'offsets',
19+
msgTarget: 'under',
20+
items: [{foreach from=$opts item=item key=k name=cbs}
2121
{literal}{{/literal}
22-
name: 'tv{$tv->id}[]'
23-
,id: 'tv{$tv->id}-{$k}'
24-
,boxLabel: '{$item.text|escape:"javascript"}'
25-
,checked: {if $item.checked}true{else}false{/if}
26-
,inputValue: {$item.value}
27-
,value: {$item.value}
22+
name: 'tv{$tv->id}[]',
23+
id: 'tv{$tv->id}-{$k}',
24+
{if $params.displayAsSwitch == 1 || $params.displayAsSwitch == 'true'}ctCls: 'display-switch',{/if}
25+
boxLabel: '{$item.text|escape:"javascript"}',
26+
checked: {if $item.checked}true{else}false{/if},
27+
inputValue: {$item.value},
28+
value: {$item.value}
2829
{literal}}{/literal}{if NOT $smarty.foreach.cbs.last},{/if}
2930
{/foreach}]
3031
{literal}}{/literal});

0 commit comments

Comments
 (0)