F
Filament16mo ago
mszabeh

Update TextInput maxValue

Hi friends. How we can use ->afterStateUpdated to change another TextInput maxValue?
6 Replies
Patrick Boivin
Patrick Boivin16mo ago
Not sure but I think max value can support a closure. You could try going through a public property on your Page component:
->afterStateUpdated(fn ($livewire) => $livewire->myMaxValue = ...)
->afterStateUpdated(fn ($livewire) => $livewire->myMaxValue = ...)
->maxValue(fn ($livewire) => $livewire->myMaxValue )
->maxValue(fn ($livewire) => $livewire->myMaxValue )
mszabeh
mszabehOP16mo ago
Thank you , I checked and this is result: Property [$myMaxValue] not found on component
LeandroFerreira
LeandroFerreira16mo ago
are you trying to do something like this?
TextInput::make('inputA')
->numeric(),
TextInput::make('inputB')
->maxValue(fn (Get $get): int => intval($get('inputA')))
TextInput::make('inputA')
->numeric(),
TextInput::make('inputB')
->maxValue(fn (Get $get): int => intval($get('inputA')))
mszabeh
mszabehOP16mo ago
Forms\Components\Select::make('variation_id') ->options(Variation::query()->where('inventory', '>' , 0)->pluck('title', 'id')) ->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->id} {$record->title} {$record->id}") ->required() ->reactive() ->afterStateUpdated(function ($state, Forms\Set $set, Forms\Get $get) { if($v = Variation::find($state)) { // I need to set maxValue of quantity to $v->inventory; } }) ->columnSpan([ 'md' => 3, ]) ->searchable(), Forms\Components\TextInput::make('quantity') ->label('Quantity') ->numeric(),
LeandroFerreira
LeandroFerreira16mo ago
same logic
TextInput::make('quantity')
->maxValue(fn (Get $get): int => Variation::find($get('variation_id'))?->inventory ?? 0)
TextInput::make('quantity')
->maxValue(fn (Get $get): int => Variation::find($get('variation_id'))?->inventory ?? 0)
mszabeh
mszabehOP16mo ago
Thank you bro. ✅
Want results from more Discord servers?
Add your server