updating the state of custom field

I can' t get the state to update, I've tried this method, as well as just calling $this->state($updtedState); without the $component.
protected function setUp(): void
{
parent::setUp();

$this->live(onBlur: true)
->afterStateUpdated(function (Component $component, ?string $state, ?string $old) {
if ($state !== null) {
$updatedState = $this->performMathOperation($state);
Log::debug($updatedState); //this is the correct value, want to reflect in text input field.

$component->state($updatedState); //input not getting updated.
}
});
}
protected function setUp(): void
{
parent::setUp();

$this->live(onBlur: true)
->afterStateUpdated(function (Component $component, ?string $state, ?string $old) {
if ($state !== null) {
$updatedState = $this->performMathOperation($state);
Log::debug($updatedState); //this is the correct value, want to reflect in text input field.

$component->state($updatedState); //input not getting updated.
}
});
}
3 Replies
Jon Mason
Jon Mason3mo ago
Does anybody have any ideas on this? Sorry to be needy, but i've tried several things, including watching the laracasts tutorial on the color picker custom field and it didn't really give me a direction to go in. Currently scouring github projects trying to figure out what I may be missing. Really haven't done much with custom fields, so I'm a bit out of my depth. It seems like what I'm doing should work..
awcodes
awcodes3mo ago
Can you verify the $state is actually not null since you are strict checking? Just my first thought. Like if it’s an empty string it won’t equate to null.
Jon Mason
Jon Mason3mo ago
it's getting past the conditional, because my new value is getting logged. It literally just isn't setting the state for some reason. Would anything about my blade file be causing it to not get handled? Doesn't seem like it, but I'm grasping at straws.
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">

<div x-data="{
state: $wire.entangle('{{ $getStatePath() }}'),
updateState() {
this.$wire.set('{{ $getStatePath() }}', this.state);
}
}">
<x-filament::input.wrapper>
<x-filament::input type="text" x-model="state" @blur="updateState" />
</x-filament::input.wrapper>
</div>
</x-dynamic-component>
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">

<div x-data="{
state: $wire.entangle('{{ $getStatePath() }}'),
updateState() {
this.$wire.set('{{ $getStatePath() }}', this.state);
}
}">
<x-filament::input.wrapper>
<x-filament::input type="text" x-model="state" @blur="updateState" />
</x-filament::input.wrapper>
</div>
</x-dynamic-component>
If I do this where I'm adding the custom field, I get the correct state, it's just not reflecting that in the input field itself...
MathInput::make('test')
->afterStateUpdated(function (?string $state, ?string $old) {
dd($state);
});
MathInput::make('test')
->afterStateUpdated(function (?string $state, ?string $old) {
dd($state);
});
ok, i put it on a blank page and it works, so I guess it's not the custom field, it's something I'm doing wrong with my $data array.
Want results from more Discord servers?
Add your server