From a3d6eb3f3cac44d120b86e4ef2d09c0a2bc45062 Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 16:50:03 +0800 Subject: [PATCH 1/5] feat: Add required functionality --- src/Html/Editor/Fields/Field.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index f3c737a..2dd2a55 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -387,4 +387,20 @@ public function className(string $className): static return $this; } + + /** + * Add an additional format to indicate if a field is required. + * + * @return $this + */ + public function required(bool $required = true) : Field + { + /** @var Field $this */ + $requiredFieldHtml = $required ? '*' : ''; + + /** @var string $label */ + $label = $this->get('label'); + + return $this->label($label.' '.$requiredFieldHtml); + } } From 064306cfed30a37fbeb4fdd3e63acdde4151eae9 Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 16:52:01 +0800 Subject: [PATCH 2/5] fix: return type to static --- src/Html/Editor/Fields/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 2dd2a55..fa4e51a 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -393,7 +393,7 @@ public function className(string $className): static * * @return $this */ - public function required(bool $required = true) : Field + public function required(bool $required = true) : static { /** @var Field $this */ $requiredFieldHtml = $required ? '*' : ''; From 5b4f380c134bf34d3e8fac9f5c4a0524a83ed6a0 Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 16:52:46 +0800 Subject: [PATCH 3/5] style: remove whitespace --- src/Html/Editor/Fields/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index fa4e51a..144cf2d 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -393,7 +393,7 @@ public function className(string $className): static * * @return $this */ - public function required(bool $required = true) : static + public function required(bool $required = true): static { /** @var Field $this */ $requiredFieldHtml = $required ? '*' : ''; From 5a9651b9d165795e94c676f0e4c950b1f4e01505 Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 16:53:47 +0800 Subject: [PATCH 4/5] fix: error with @var --- src/Html/Editor/Fields/Field.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 144cf2d..1160e82 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -395,10 +395,7 @@ public function className(string $className): static */ public function required(bool $required = true): static { - /** @var Field $this */ $requiredFieldHtml = $required ? '*' : ''; - - /** @var string $label */ $label = $this->get('label'); return $this->label($label.' '.$requiredFieldHtml); From f6020cf11125025e7c854062ee65b8690c7f0267 Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 17:03:26 +0800 Subject: [PATCH 5/5] fix: error with $label --- src/Html/Editor/Fields/Field.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 1160e82..f0eb20a 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -389,7 +389,7 @@ public function className(string $className): static } /** - * Add an additional format to indicate if a field is required. + * Add a format to indicate if a field is required. * * @return $this */ @@ -398,6 +398,6 @@ public function required(bool $required = true): static $requiredFieldHtml = $required ? '*' : ''; $label = $this->get('label'); - return $this->label($label.' '.$requiredFieldHtml); + return $this->label(($label ?? '').' '.$requiredFieldHtml); } }