I think lte validator is not working

Forms\Components\Toggle::make('full_refund') ->columnSpan(2) ->reactive() ->afterStateUpdated( function ($state, callable $set, RelationManager $livewire) { $set('amount', round($livewire->ownerRecord->grand_total, 2)); } ), Forms\Components\TextInput::make('amount') ->numeric() ->lte(function ($state, callable $set, RelationManager $livewire) { return round($livewire->ownerRecord->grand_total, 2); }) , It has the same value round($livewire->ownerRecord->grand_total, 2) but it shows an error
4 Replies
fede8100
fede8100OP2y ago
I had to use ->rules([ function (RelationManager $livewire) { return function (string $attribute, $value, \Closure $fail) use($livewire) { if (round($value, 2) > round($livewire->ownerRecord->grand_total, 2)) { $fail("The amount can't be bigger than the order's amount."); } }; }, ])
sotjj
sotjj2y ago
I am having the same issue and receiving this error when using ->lte validation: The amount field must be less than or equal to data.9999.99. I handled this with a regex validation instead: ->regex('/^-?[0-9]{1,4}(?:.[0-9]{1,2})?$/'), This allows for positive and negative numbers and only up to two decimal places with a range of -9999.99 to 9999.99
steven.chang
steven.chang8mo ago
I had the same issue. @fede8100 You made my day 😄
Dennis Koch
Dennis Koch8mo ago
The method defines the field name and not the value.

Did you find this page helpful?