Dispatch event from afterStateUpdated to another field?

Hey guys, I have a builder field with a afterStateUpdated function where I want to dispatch the current value to a custom field. I tryed livewire listener but this didnt worked.
Is this possible? Or could I force a rerender of the custom field by manipulating its state? Thanks.
Builder::make('content')
->blocks(
PageBlocks::make())
->live()
->afterStateUpdated(function(Get $get, Set $set, Livewire $livewire) {
$livewire->dispatch('updateData', $get('content'));
$set('preview', $get('content'));
}),
Builder::make('content')
->blocks(
PageBlocks::make())
->live()
->afterStateUpdated(function(Get $get, Set $set, Livewire $livewire) {
$livewire->dispatch('updateData', $get('content'));
$set('preview', $get('content'));
}),
#[On('updateData')]
public function updateData(array $data)
{
dd($data);
}
#[On('updateData')]
public function updateData(array $data)
{
dd($data);
}
2 Replies
LeandroFerreira
Did you create a preview custom field ? I think $set('preview', $get('content')); should work and you are able to access the preview state in the view using $getState()
<!-- resources/views/forms/components/preview.blade.php -->
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
{{ var_export($getState()) }}

</x-dynamic-component>
<!-- resources/views/forms/components/preview.blade.php -->
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>
{{ var_export($getState()) }}

</x-dynamic-component>
EpicKau
EpicKauOP3d ago
Dc dont let me post my code so here is a screenshot. My Idea was to create a iframe that renders the page content (the builder field). The iframe is only needed for manipulationg the browser window size (different device sizes). It works but after the contet changed the iframe content didnt refresh. Is there a "haschanged" hook in the field class that I can use for this?
No description

Did you find this page helpful?