charlie
charlie
FFilament
Created by charlie on 11/14/2024 in #❓┊help
$getRecord() in a form changes when I click on an action button or a relation manager tab
Hi, I'm trying to create a custom field as explained here: https://filamentphp.com/docs/3.x/forms/fields/custom#custom-field-classes From the generated view, if I dump record like that:
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
<!-- Interact with the `state` property in Alpine.js -->

@dump($getRecord())

</div>
</x-dynamic-component>
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
<div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
<!-- Interact with the `state` property in Alpine.js -->

@dump($getRecord())

</div>
</x-dynamic-component>
It works fine, until I click on a button launching a modal or a Tab switching to a different RelationManager below the form. The record seems to be emptied, and the code in custom field can't access to the record anymore unless I refresh the page... Is it normal? And what could I do?
5 replies
FFilament
Created by charlie on 10/24/2024 in #❓┊help
Can't use $get inside recordSelectOptionsQuery: any workaround?
Hi, I didn't find the answer on this discord, nor in the docs. What I'm trying to do: Modify the query of the attach action select based on another field The code:
Tables\Actions\AttachAction::make()
->form(function (AttachAction $action): array {
return [

// The field I want to get...
Forms\Components\Toggle::make('mine_only')
->live()
->dehydrated(false),

$action->getRecordSelect(),
];
})
->recordSelectOptionsQuery(
function (Builder $query, $livewire, $get) {

dd($livewire); // Works but I don't know if I can "get" from this

dd($get('mine_only')); // Doesn't work: (An attempt was made to evaluate a closure for [Filament\Tables\Actions\AttachAction], but [$get] was unresolvable.)

// This should be returned if Toggle is on
return $query->whereHas('users',
fn(Builder $query) => $query->where('users.id', auth()->user()->id)
);

// Else if Toggle is off return the base query
return $query;
}
)
Tables\Actions\AttachAction::make()
->form(function (AttachAction $action): array {
return [

// The field I want to get...
Forms\Components\Toggle::make('mine_only')
->live()
->dehydrated(false),

$action->getRecordSelect(),
];
})
->recordSelectOptionsQuery(
function (Builder $query, $livewire, $get) {

dd($livewire); // Works but I don't know if I can "get" from this

dd($get('mine_only')); // Doesn't work: (An attempt was made to evaluate a closure for [Filament\Tables\Actions\AttachAction], but [$get] was unresolvable.)

// This should be returned if Toggle is on
return $query->whereHas('users',
fn(Builder $query) => $query->where('users.id', auth()->user()->id)
);

// Else if Toggle is off return the base query
return $query;
}
)
Thanks for the help!
4 replies