Skip to content

Commit a3d6eb3

Browse files
authored
feat: Add required functionality
1 parent bfd5db4 commit a3d6eb3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Html/Editor/Fields/Field.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,20 @@ public function className(string $className): static
387387

388388
return $this;
389389
}
390+
391+
/**
392+
* Add an additional format to indicate if a field is required.
393+
*
394+
* @return $this
395+
*/
396+
public function required(bool $required = true) : Field
397+
{
398+
/** @var Field $this */
399+
$requiredFieldHtml = $required ? '<span class="text-red-500">*</span>' : '';
400+
401+
/** @var string $label */
402+
$label = $this->get('label');
403+
404+
return $this->label($label.' '.$requiredFieldHtml);
405+
}
390406
}

0 commit comments

Comments
 (0)