Skip to content

Commit

Permalink
add default value
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Sep 17, 2021
1 parent e958ced commit 2c32188
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Customizable Radio Buttons Field Changelog

## 1.0.3 - 2021-09-16

### Added

- Add a simple way to set a default value to every field.
- Add some instructions to the field settings.

## 1.0.2 - 2021-09-01

### Fixed

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

## 1.0.1 - 2019-09-15

### Fixed

- Publishing images to cpresources.

## 1.0.0 - 2019-04-06
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "codemonauts/craft-customizable-radio-buttons-field",
"description": "Craft CMS plugin to add a radio buttons field, customizable with CSS classes, icons, images and text.",
"version": "1.0.2",
"version": "1.0.3",
"type": "craft-plugin",
"keywords": [
"craft",
Expand Down Expand Up @@ -36,6 +36,7 @@
"class": "codemonauts\\buttons\\Buttons",
"name": "Customizable Radio Buttons Field",
"description": "Radio buttons field, customizable with CSS classes, icons, images and text.",
"changelogUrl": "https://github.com/codemonauts/craft-customizable-radio-buttons-field/blob/master/CHANGELOG.md",
"hasCpSection": false,
"hasSettings": false
}
Expand Down
22 changes: 20 additions & 2 deletions src/fields/Buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Buttons extends Field implements PreviewableFieldInterface
*/
public $configHandle = '';

/**
* @var string Default value
*/
public $defaultValue = '';

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -59,15 +64,28 @@ public function getSettingsHtml()
];
}

return Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'selectField', [
$html = Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'selectField', [
[
'label' => Craft::t('buttons', 'Button group'),
'instructions' => Craft::t('buttons', 'The button group from the config file to use.'),
'id' => 'configHandle',
'name' => 'configHandle',
'options' => $options,
'value' => $this->configHandle,
],
]);

$html .= Craft::$app->getView()->renderTemplateMacro('_includes/forms', 'textField', [
[
'label' => Craft::t('buttons', 'Default value'),
'instructions' => Craft::t('buttons', 'The default value of the field. If empty, no button will be preselected.'),
'id' => 'defaultValue',
'name' => 'defaultValue',
'value' => $this->defaultValue,
],
]);

return $html;
}

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

return Craft::$app->getView()->renderTemplate('buttons/input', [
'name' => $this->handle,
'value' => $value,
'value' => $value ?? $this->defaultValue,
'field' => $this,
'buttons' => $buttons,
]);
Expand Down
3 changes: 3 additions & 0 deletions src/translations/de/buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
return [
'Customizable Radio Buttons' => 'Individuelle Radio-Buttons',
'Button group' => 'Schalterkonfiguration',
'Default value' => 'Standardwert',
'The button group from the config file to use.' => 'Die Button-Gruppe aus der Konfigurationsdatei die verwendet werden soll.',
'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.'
];

0 comments on commit 2c32188

Please sign in to comment.