multiply 2 Input and show the result in a third input
Hey guys, i need multipley 2 input when i put the second value and show the result in other TextInput, in this case in
imc
i have my code like this:
Forms\Components\TextInput::make('size')
->label('Altura')
->live()
->required(),
Forms\Components\TextInput::make('weight')
->label('Peso Kg.')
->live()
->required(),
Forms\Components\TextInput::make('imc')
->label('Indice de masa corporal')
->required(),
in this case i need multiply size and weight and show the total in imc, but i need square size, when i put the value in weight and multiply, how can do this in Forms?
Thank you guys!4 Replies
you can use
$get and $set
Its working @Lara Zeus thank you for the tips... work really cool
i add a debounce only for fix a problem if any add 2 or more number in weight, and this is the code:
Forms\Components\TextInput::make('weight')
->label('Peso Kg.')
->numeric()
->live(debounce: 1500)
->afterStateUpdated(fn(Set $set, Get $get)=>$set('imc', $get('weight') / ($get('size') * $get('size')) ))
->required(),
that prefect also you can use
->live(onBlur: true)
to only update when the user "leave" the input πi will test it, thank you bro!