Skip to content

Commit ed5aa78

Browse files
authored
Merge pull request #16308 from filamentphp/required-fieldset
Required fieldset
2 parents e1dc346 + 01f6d94 commit ed5aa78

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

packages/forms/resources/views/components/fieldset.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<x-filament::fieldset
22
:label="$getLabel()"
33
:label-hidden="$isLabelHidden()"
4+
:required="isset($isMarkedAsRequired) ? $isMarkedAsRequired() : false"
45
:attributes="
56
\Filament\Support\prepare_inherited_attributes($attributes)
67
->merge([

packages/forms/src/Components/Fieldset.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class Fieldset extends Component implements CanEntangleWithSingularRelationships
1010
{
11+
use Concerns\CanBeMarkedAsRequired;
1112
use Concerns\EntanglesStateWithSingularRelationship;
1213

1314
/**
@@ -36,4 +37,9 @@ protected function setUp(): void
3637

3738
$this->columns(2);
3839
}
40+
41+
public function isRequired(): bool
42+
{
43+
return false;
44+
}
3945
}

packages/forms/src/Components/MorphToSelect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class MorphToSelect extends Component
1212
{
1313
use Concerns\CanAllowHtml;
14+
use Concerns\CanBeMarkedAsRequired;
1415
use Concerns\CanBeNative;
1516
use Concerns\CanBePreloaded;
1617
use Concerns\CanBeSearchable;

packages/support/resources/views/components/fieldset.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@props([
22
'label' => null,
33
'labelHidden' => false,
4+
'required' => false,
45
])
56

67
<fieldset
@@ -17,7 +18,9 @@
1718
'sr-only' => $labelHidden,
1819
])
1920
>
20-
{{ $label }}
21+
{{-- Deliberately poor formatting to ensure that the asterisk sticks to the final word in the label. --}}
22+
{{ $label }}@if ($required)<sup class="text-danger-600 dark:text-danger-400 font-medium">*</sup>
23+
@endif
2124
</legend>
2225
@endif
2326

0 commit comments

Comments
 (0)