$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?
1 Reply
charlie
charlieOP6d ago
Solution: Adding wire:ignore to the parent div seems to do the trick! Unfortunately, adding wire:ignore prevents field to refresh (it makes sense)... I solved it querying model again:
MyModel::find($getRecord()->id)
MyModel::find($getRecord()->id)
Not ideal, but surprisingly id keeps working unlike other attributes. I'm curious about the reason behind this behaviour, and better alternatives if any
Want results from more Discord servers?
Add your server