I have these 2 fields. The ref_no with formatStateUsing() and ref_no without this method formatStateUsing(). Now the method formatStateUsing() affects both ref_no.
How do I prevent this?
TextInput::make('ref_no')
->label('Reference No.')
->reactive()
->disabled()
->formatStateUsing(fn ($state) => Str::before($state, '-'))
->columnSpan(1),
TextInput::make('ref_no')
->label('Reference No.')
->columnSpan(2),
I solved the problem by having this. First i added afterStateHydrated() then add a prefix then set the step_two_ref_no to the unmodified value of ref_no
TextInput::make('ref_no')
->label('Reference No.')
->reactive()
->disabled()
->afterStateHydrated(function ($component, $state, $set) {
$prefix = Str::before($state, '-');
$component->state($prefix);
$set('step_two_ref_no', $state);
})
->columnSpan(1),
TextInput::make('step_two_ref_no')
->label('Reference No.')
->columnSpan(2),
I have these 2 fields. The ref_no with formatStateUsing() and ref_no without this method formatStateUsing(). Now the method formatStateUsing() affects both ref_no.
How do I prevent this?
TextInput::make('ref_no')
->label('Reference No.')
->reactive()
->disabled()
->formatStateUsing(fn ($state) => Str::before($state, '-'))
->columnSpan(1),
TextInput::make('ref_no')
->label('Reference No.')
->columnSpan(2),
I solved the problem by having this. First i added afterStateHydrated() then add a prefix then set the step_two_ref_no to the unmodified value of ref_no
TextInput::make('ref_no')
->label('Reference No.')
->reactive()
->disabled()
->afterStateHydrated(function ($component, $state, $set) {
$prefix = Str::before($state, '-');
$component->state($prefix);
$set('step_two_ref_no', $state);
})
->columnSpan(1),
TextInput::make('step_two_ref_no')
->label('Reference No.')
->columnSpan(2),
Share
Improve this question
edited Mar 27 at 7:53
Nelson Castro
asked Mar 27 at 3:50
Nelson CastroNelson Castro
234 bronze badges
1 Answer
Reset to default 1All form fields should have a unique name in FilamentPHP, as stated by the docs (emphasis mine):
Fields may be created using the static make() method, passing its unique name. The name of the field should correspond to a property on your Livewire component. You may use “dot notation” to bind fields to keys in arrays.
I'm not entirely sure about the Filament internals, but I assume Filament/Livewire totally relies on the name of the inputs as the only way to distinguish between those. Hence, the results of the method you call on one of the fields, may also get applied to any other field with the same name.