diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index f3c737a..f0eb20a 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -387,4 +387,17 @@ public function className(string $className): static return $this; } + + /** + * Add a format to indicate if a field is required. + * + * @return $this + */ + public function required(bool $required = true): static + { + $requiredFieldHtml = $required ? '*' : ''; + $label = $this->get('label'); + + return $this->label(($label ?? '').' '.$requiredFieldHtml); + } }