F
Filament16mo ago
bionary

Additional Info Fields in Form

What is the best way to go about adding supplemental data fields to a form? But the catch is, it shouldn't be handled as form fields. (not saved) I often find that including stuff like parent-relationship info in or near the form is helpful sometimes. I tried using ViewField and making sure that my view had non-form elements in it, but when upon saving the form, filament is expecting a saved data field for "parent_properties" as setup below.
ViewField::make('parent_properties')->view('filament.forms.components.text-display')
ViewField::make('parent_properties')->view('filament.forms.components.text-display')
//text-display.blade.php
<x-dynamic-component
:component="$getFieldWrapperView()"
:id="$getId()"
:label="$getLabel()"
:label-sr-only="$isLabelHidden()"
:helper-text="$getHelperText()"
:hint="$getHint()"
:hint-action="$getHintAction()"
:hint-color="$getHintColor()"
:hint-icon="$getHintIcon()"
:required="$isRequired()"
:state-path="$getStatePath()"
>

<p>Project: {{$this->record->article->project->name}}</p>
<p>Category: {{$this->record->article->category->path}}</p>
<p>Article: {{$this->record->article->title}}</p>
<p>Contractor: {{$this->record->contractor->name}}</p>
</x-dynamic-component>
//text-display.blade.php
<x-dynamic-component
:component="$getFieldWrapperView()"
:id="$getId()"
:label="$getLabel()"
:label-sr-only="$isLabelHidden()"
:helper-text="$getHelperText()"
:hint="$getHint()"
:hint-action="$getHintAction()"
:hint-color="$getHintColor()"
:hint-icon="$getHintIcon()"
:required="$isRequired()"
:state-path="$getStatePath()"
>

<p>Project: {{$this->record->article->project->name}}</p>
<p>Category: {{$this->record->article->category->path}}</p>
<p>Article: {{$this->record->article->title}}</p>
<p>Contractor: {{$this->record->contractor->name}}</p>
</x-dynamic-component>
I know I can use one of the mutateData...functions to strip the form input prior to being saved, but I can see this getting sloppy and bloated quickly. What is a better approach? Thanks!
2 Replies
awcodes
awcodes16mo ago
->dehydrate(false) on the ViewField maybe. Or use a View instead of a ViewField.?
bionary
bionary16mo ago
okay let me try Heck yeah! using View worked! nice one thanks Adam Final code to help future travelers:
//form
View::make('parent_properties')->view('filament.forms.components.text-display'),
//form
View::make('parent_properties')->view('filament.forms.components.text-display'),
//text-display.blade.php
<div>
<p>Project: {{$this->record->article->project->name}}</p>
<p>Category: {{$this->record->article->category->path}}</p>
<p>Article: {{$this->record->article->title}}</p>
<p>Contractor: {{$this->record->contractor->name}}</p>
</div>
//text-display.blade.php
<div>
<p>Project: {{$this->record->article->project->name}}</p>
<p>Category: {{$this->record->article->category->path}}</p>
<p>Article: {{$this->record->article->title}}</p>
<p>Contractor: {{$this->record->contractor->name}}</p>
</div>