Skip to content

Commit 2c32188

Browse files
committed
add default value
1 parent e958ced commit 2c32188

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# Customizable Radio Buttons Field Changelog
22

3+
## 1.0.3 - 2021-09-16
4+
5+
### Added
6+
7+
- Add a simple way to set a default value to every field.
8+
- Add some instructions to the field settings.
9+
310
## 1.0.2 - 2021-09-01
411

512
### Fixed
13+
614
- Add wrap and gap to the buttons (thanks to @emsuiko).
715
- Fixed background color of icon.
816
- Fixed a bug when two or more same configurations were used in one tab/ matrix block.
917

1018
## 1.0.1 - 2019-09-15
1119

1220
### Fixed
21+
1322
- Publishing images to cpresources.
1423

1524
## 1.0.0 - 2019-04-06

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codemonauts/craft-customizable-radio-buttons-field",
33
"description": "Craft CMS plugin to add a radio buttons field, customizable with CSS classes, icons, images and text.",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"type": "craft-plugin",
66
"keywords": [
77
"craft",
@@ -36,6 +36,7 @@
3636
"class": "codemonauts\\buttons\\Buttons",
3737
"name": "Customizable Radio Buttons Field",
3838
"description": "Radio buttons field, customizable with CSS classes, icons, images and text.",
39+
"changelogUrl": "https://github.com/codemonauts/craft-customizable-radio-buttons-field/blob/master/CHANGELOG.md",
3940
"hasCpSection": false,
4041
"hasSettings": false
4142
}

src/fields/Buttons.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class Buttons extends Field implements PreviewableFieldInterface
2929
*/
3030
public $configHandle = '';
3131

32+
/**
33+
* @var string Default value
34+
*/
35+
public $defaultValue = '';
36+
3237
/**
3338
* @inheritdoc
3439
*/
@@ -59,15 +64,28 @@ public function getSettingsHtml()
5964
];
6065
}
6166

62-
return Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'selectField', [
67+
$html = Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'selectField', [
6368
[
6469
'label' => Craft::t('buttons', 'Button group'),
70+
'instructions' => Craft::t('buttons', 'The button group from the config file to use.'),
6571
'id' => 'configHandle',
6672
'name' => 'configHandle',
6773
'options' => $options,
6874
'value' => $this->configHandle,
6975
],
7076
]);
77+
78+
$html .= Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'textField', [
79+
[
80+
'label' => Craft::t('buttons', 'Default value'),
81+
'instructions' => Craft::t('buttons', 'The default value of the field. If empty, no button will be preselected.'),
82+
'id' => 'defaultValue',
83+
'name' => 'defaultValue',
84+
'value' => $this->defaultValue,
85+
],
86+
]);
87+
88+
return $html;
7189
}
7290

7391
/**
@@ -96,7 +114,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
96114

97115
return Craft::$app->getView()->renderTemplate('buttons/input', [
98116
'name' => $this->handle,
99-
'value' => $value,
117+
'value' => $value ?? $this->defaultValue,
100118
'field' => $this,
101119
'buttons' => $buttons,
102120
]);

src/translations/de/buttons.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
return [
44
'Customizable Radio Buttons' => 'Individuelle Radio-Buttons',
55
'Button group' => 'Schalterkonfiguration',
6+
'Default value' => 'Standardwert',
7+
'The button group from the config file to use.' => 'Die Button-Gruppe aus der Konfigurationsdatei die verwendet werden soll.',
8+
'The default value of the field. If empty, no button will be preselected.' => 'Der Standardwert des Feldes. Ist dieser leer, wird kein Button vorausgewählt.'
69
];

0 commit comments

Comments
 (0)