From f9a1a9bb51c790f32fb3b24352d4798ea00dda3a Mon Sep 17 00:00:00 2001 From: MacBook-Joey Date: Tue, 27 Jul 2021 12:23:10 +0200 Subject: [PATCH] Create disabled functionality for formal --- src/FormAl/ElementBase.php | 18 ++++++++++++++++++ src/FormAl/Elements/Button.php | 4 ++++ src/FormAl/Elements/Checkbox.php | 4 ++++ src/FormAl/Elements/Chosen.php | 4 ++++ src/FormAl/Elements/Colorpicker.php | 6 +++++- src/FormAl/Elements/DateNoTimepicker.php | 4 ++++ src/FormAl/Elements/Datepicker.php | 9 +-------- src/FormAl/Elements/ImageUploadToServer.php | 4 ++++ src/FormAl/Elements/Input.php | 4 ++++ src/FormAl/Elements/Integer.php | 4 ++++ src/FormAl/Elements/MultiSelect.php | 4 ++++ src/FormAl/Elements/PositiveInteger.php | 4 ++++ src/FormAl/Elements/Radio.php | 5 ++++- src/FormAl/Elements/Select.php | 4 ++++ src/FormAl/Elements/Textarea.php | 6 +++++- 15 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/FormAl/ElementBase.php b/src/FormAl/ElementBase.php index 9c7bebc..a543b71 100644 --- a/src/FormAl/ElementBase.php +++ b/src/FormAl/ElementBase.php @@ -36,6 +36,8 @@ abstract class ElementBase private $folded = false; /** @var bool */ protected $hasAutoFill = true; + /** @var bool */ + protected $disabled = false; /** * @return string @@ -267,6 +269,22 @@ public function isFolded() return $this->folded; } + /** + * @param bool $bool + */ + public function setDisabled($bool) + { + $this->disabled = $bool; + } + + /** + * @return bool + */ + public function isDisabled() + { + return $this->disabled; + } + /** * @return string|null */ diff --git a/src/FormAl/Elements/Button.php b/src/FormAl/Elements/Button.php index 6af3e6b..aa23ec2 100644 --- a/src/FormAl/Elements/Button.php +++ b/src/FormAl/Elements/Button.php @@ -70,6 +70,10 @@ public function render() ->attr('style', "max-width: 400px;") ->addText($this->text); + if ($this->isDisabled()) { + $element->attr('disabled', true); + } + return $element->render(); } } diff --git a/src/FormAl/Elements/Checkbox.php b/src/FormAl/Elements/Checkbox.php index 0a05735..cc7d753 100644 --- a/src/FormAl/Elements/Checkbox.php +++ b/src/FormAl/Elements/Checkbox.php @@ -61,6 +61,10 @@ public function render() ->attr('checked', $checked) ->attr('value', $this->trueValue); + if ($this->isDisabled()) { + $element->attr('disabled', true); + } + $tooltip = ""; if (empty($this->getTooltip()) == false) { $tooltip = " " . $this->getTooltip(); diff --git a/src/FormAl/Elements/Chosen.php b/src/FormAl/Elements/Chosen.php index 797ada6..70922be 100644 --- a/src/FormAl/Elements/Chosen.php +++ b/src/FormAl/Elements/Chosen.php @@ -51,6 +51,10 @@ public function render() $element->attr('multiple', 'multiple'); $element->attr('class', 'chosen-select form-control'); + if ($this->isDisabled()) { + $element->attr('disabled', 'disabled'); + } + $this->optGroups($element, $this->options); return $element->render() . "