Reset multiple field when boolean update

Hi, I have this Section in my form, where we can manage the Duration of a service. I have 3 field, one for the base time, one for a second time if needed, and the last one, a toggle to say if the duration is variable, on quotation. I need the 2 first fields (duration and max_duration) tu be null when I update the duration_quotation, but I can't manage to reset both :/
Section::make('Gestion de la durée')
->icon('carbon-time')
->columns(2)
->schema([
TextInput::make('duration')
->requiredUnless('price_quotation', true)
->label('Durée (minutes)')
->numeric()
->hidden(
fn (Get $get): bool => $get('duration_quotation') == true
),
TextInput::make('max_duration')
->label('Durée (fourchette haute)')
->numeric()
->hidden(
fn (Get $get): bool => $get('duration_quotation') == true
),
Toggle::make('duration_quotation')
->label('Durée variable')
->reactive()
->afterStateUpdated(
fn ($state, callable $set) => $state
? $set('duration', null)
: $set('duration', 'hidden'),
),
]),
Section::make('Gestion de la durée')
->icon('carbon-time')
->columns(2)
->schema([
TextInput::make('duration')
->requiredUnless('price_quotation', true)
->label('Durée (minutes)')
->numeric()
->hidden(
fn (Get $get): bool => $get('duration_quotation') == true
),
TextInput::make('max_duration')
->label('Durée (fourchette haute)')
->numeric()
->hidden(
fn (Get $get): bool => $get('duration_quotation') == true
),
Toggle::make('duration_quotation')
->label('Durée variable')
->reactive()
->afterStateUpdated(
fn ($state, callable $set) => $state
? $set('duration', null)
: $set('duration', 'hidden'),
),
]),
Thx in advance 🙂
Solution:
```php ->afterStateUpdated( function ($state, callable $set) { if ($state) { $set('duration', null);...
Jump to solution
2 Replies
Solution
cheesegrits
cheesegrits14mo ago
->afterStateUpdated(
function ($state, callable $set) {
if ($state) {
$set('duration', null);
$set('max_duration', null);
}
}
),
->afterStateUpdated(
function ($state, callable $set) {
if ($state) {
$set('duration', null);
$set('max_duration', null);
}
}
),
Charly / Toufloux
Charly / TouflouxOP14mo ago
Haan ok, the syntax with the fn and the arrow just lost me :x Thank you ! 🙂
Want results from more Discord servers?
Add your server