| Closure $schema */ final public function __construct(array | Closure $schema = []) { $this->schema($schema); } /** * @param array | Closure $schema */ public static function make(array | Closure $schema = []): static { $static = app(static::class, ['schema' => $schema]); $static->configure(); return $static; } protected function setUp(): void { parent::setUp(); $this->gap(false); } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function aboveLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::ABOVE_LABEL_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function belowLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::BELOW_LABEL_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function beforeLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::BEFORE_LABEL_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function afterLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::AFTER_LABEL_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function beforeContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::BEFORE_CONTENT_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function afterContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::AFTER_CONTENT_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function aboveContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::ABOVE_CONTENT_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function belowContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::BELOW_CONTENT_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function aboveErrorMessage(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::ABOVE_ERROR_MESSAGE_SCHEMA_KEY); return $this; } /** * @param array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components */ public function belowErrorMessage(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static { $this->childComponents($components, static::BELOW_ERROR_MESSAGE_SCHEMA_KEY); return $this; } protected function makeChildSchema(string $key): Schema { $schema = parent::makeChildSchema($key); if ($key === static::AFTER_LABEL_SCHEMA_KEY) { $schema->alignEnd(); } return $schema; } protected function configureChildSchema(Schema $schema, string $key): Schema { $schema = parent::configureChildSchema($schema, $key); $schema->fieldWrapperView('filament-forms::plain-field-wrapper'); if (in_array($key, [ static::BEFORE_LABEL_SCHEMA_KEY, static::AFTER_LABEL_SCHEMA_KEY, static::ABOVE_CONTENT_SCHEMA_KEY, static::BELOW_CONTENT_SCHEMA_KEY, static::ABOVE_ERROR_MESSAGE_SCHEMA_KEY, static::BELOW_ERROR_MESSAGE_SCHEMA_KEY, ])) { $schema ->inline() ->embeddedInParentComponent() ->modifyActionsUsing(fn (Action $action) => $action ->defaultSize(Size::Small) ->defaultView(Action::LINK_VIEW)) ->modifyActionGroupsUsing(fn (ActionGroup $actionGroup) => $actionGroup->defaultSize(Size::Small)); } return $schema; } public function toEmbeddedHtml(): string { // Custom error collection from child fields /** @var MessageBag $errors */ $errors = view()->shared('errors') instanceof ViewErrorBag ? view()->shared('errors')->getBag('default') : new MessageBag; $errorMessage = null; $errorMessages = []; $areHtmlErrorMessagesAllowed = false; foreach ($this->getChildComponentContainer()->getComponents() as $childComponent) { if (! ($childComponent instanceof Field)) { continue; } $statePath = $childComponent->getStatePath(); if (blank($statePath)) { continue; } if ($errors->has($statePath)) { if ($childComponent->shouldShowAllValidationMessages()) { $errorMessages = $errors->get($statePath); } else { $errorMessage = $errors->first($statePath); } $areHtmlErrorMessagesAllowed = $childComponent->areHtmlValidationMessagesAllowed(); break; } if (! ($childComponent instanceof HasNestedRecursiveValidationRules)) { continue; } if ($errors->has("{$statePath}.*")) { if ($childComponent->shouldShowAllValidationMessages()) { $errorMessages = Arr::flatten($errors->get("{$statePath}.*")); } else { $errorMessage = $errors->first("{$statePath}.*"); } $areHtmlErrorMessagesAllowed = $childComponent->areHtmlValidationMessagesAllowed(); break; } } // A single message renders as `

`; only multiple messages render as // `

  • `, so collapse a one-element list into the scalar form. if (count($errorMessages) === 1) { $errorMessage = Arr::first($errorMessages); $errorMessages = []; } $hasError = filled($errorMessage) || filled($errorMessages); // Inner content $groupId = $this->getId(); $groupLabelId = (filled($groupId) && filled($this->getLabel())) ? "{$groupId}-label" : null; $groupErrorId = (filled($groupId) && $hasError) ? "{$groupId}-error" : null; $innerAttributes = (new FilamentComponentAttributeBag) ->merge([ 'id' => $groupId, 'role' => 'group', 'aria-labelledby' => $groupLabelId, 'aria-describedby' => $groupErrorId, 'aria-invalid' => $hasError ? 'true' : null, ], escape: false) ->merge($this->getExtraAttributes(), escape: false) ->class(['fi-sc-fused-group']); $innerHtml = '
    toHtml() . '>' . $this->getChildSchema()->toHtml() . '
    '; $fieldWrapperView = $this->getFieldWrapperView(); $isDefaultFieldWrapperView = $fieldWrapperView === 'filament-forms::field-wrapper'; if ( (! $isDefaultFieldWrapperView) || ViewComponent::hasPublishedEmbeddedViewOverride('filament-forms::components.field-wrapper') ) { $absoluteView = $isDefaultFieldWrapperView ? 'filament-forms::components.field-wrapper' : (string) (str($fieldWrapperView)->contains('::') ? str($fieldWrapperView)->replaceFirst('::', '::components.') : str("components.{$fieldWrapperView}")); if (view()->exists($absoluteView)) { return view($absoluteView, [ 'field' => $this, 'slot' => new ComponentSlot($innerHtml), 'errorMessage' => $errorMessage, 'errorMessages' => $errorMessages, 'areHtmlErrorMessagesAllowed' => $areHtmlErrorMessagesAllowed, 'shouldShowAllValidationMessages' => filled($errorMessages), ])->toHtml(); } return $this->renderWrapperBladeComponent( $fieldWrapperView, new ComponentSlot($innerHtml), new FilamentComponentAttributeBag([ 'field' => $this, 'error-message' => $errorMessage, 'error-messages' => $errorMessages, 'are-html-error-messages-allowed' => $areHtmlErrorMessagesAllowed, 'should-show-all-validation-messages' => filled($errorMessages), ]), ); } // Field wrapper rendering (inline, same as `Field::wrapEmbeddedHtml()` but with custom errors) $hasInlineLabel = $this->hasInlineLabel(); $id = $this->getId(); $isDisabled = $this->isDisabled(); $label = $this->getLabel(); $labelSrOnly = $this->isLabelHidden(); $required = $this->isMarkedAsRequired(); $aboveLabelSchema = $this->getChildSchema(static::ABOVE_LABEL_SCHEMA_KEY)?->toHtmlString(); $belowLabelSchema = $this->getChildSchema(static::BELOW_LABEL_SCHEMA_KEY)?->toHtmlString(); $beforeLabelSchema = $this->getChildSchema(static::BEFORE_LABEL_SCHEMA_KEY)?->toHtmlString(); $afterLabelSchema = $this->getChildSchema(static::AFTER_LABEL_SCHEMA_KEY)?->toHtmlString(); $aboveContentSchema = $this->getChildSchema(static::ABOVE_CONTENT_SCHEMA_KEY)?->toHtmlString(); $belowContentSchema = $this->getChildSchema(static::BELOW_CONTENT_SCHEMA_KEY)?->toHtmlString(); $beforeContentSchema = $this->getChildSchema(static::BEFORE_CONTENT_SCHEMA_KEY)?->toHtmlString(); $afterContentSchema = $this->getChildSchema(static::AFTER_CONTENT_SCHEMA_KEY)?->toHtmlString(); $aboveErrorMessageSchema = $this->getChildSchema(static::ABOVE_ERROR_MESSAGE_SCHEMA_KEY)?->toHtmlString(); $belowErrorMessageSchema = $this->getChildSchema(static::BELOW_ERROR_MESSAGE_SCHEMA_KEY)?->toHtmlString(); $wrapperAttributes = (new FilamentComponentAttributeBag) ->merge($this->getExtraFieldWrapperAttributes(), escape: false) ->class([ 'fi-fo-field', 'fi-fo-field-has-inline-label' => $hasInlineLabel, ]); $inlineLabelVerticalAlignment = VerticalAlignment::Start; ob_start(); ?>
    toHtml() ?>>
    class([ 'fi-fo-field-label-col', "fi-vertical-align-{$inlineLabelVerticalAlignment->value}" => $hasInlineLabel, ])->toHtml() ?> > toHtml() ?>
    class([ 'fi-fo-field-label-ctn', ($label instanceof ComponentSlot) ? $label->attributes->get('class') : null, ])->toHtml() ?> > toHtml() ?> toHtml() ?>
    toHtml() ?>
    toHtml() ?>
    toHtml() ?>
    toHtml() ?>
    toHtml() ?> toHtml() ?>
      id="-error" class="fi-fo-field-wrp-error-list">
    id="-error" class="fi-fo-field-wrp-error-message">

    id="-error" class="fi-fo-field-wrp-error-message">

    toHtml() ?>
    getDefaultChildComponents() as $component) { if (! ($component instanceof Field)) { continue; } if ($component->isMarkedAsRequired()) { return true; } } return false; } }