Suggestion for dependant fields
Can someone suggest me what is the best approach for dependant fields..
In my case, I want my input total_price to be dependant to:
1. room_id, which is later will have to get a price attribute from room model, required
2. discount, numeric input, not required
3. additional_services (with repeater), has name and price attribute, can be 0 items or not required.
So later, the input price will be a calculated data of those above 3 inputs.
Currently the form is in resource class..
I'm using filament v2.
Solution:Jump to solution
thanks for your response before..
I've decided to calculate what's in repeater in afterCreate method.....
13 Replies
Can someone help me?
You could use Total Price as a placeholder and calculate it using the values from other fields. If you’d like a suggestion, please share some of the code you’re using.
How can I submit the form with what is defined in total_price placeholder?
Change placeholder to default.
else change placeholder to fromatStateUsing and condition if value is empty run function.
i've tried using default and fromatStateUsing with the same function as placeholder above, but the value isn't updated after changing or filling all of 3 other inputs, still 0
Ahh it's disabled, PI missed that. why disable it if you want to save it?
use mutateBeforeSave if you want it to set what it will be
yup, I don't want the user to edit the total price directly..
i'm still in filament v2..
did you mean mutateFormDataBeforeCreate?
how can I calculate my repeater data there?
use a place holder, set the placeholder content and make it reactive.
It depends but:
https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-data-before-saving
or use an observer.
sorry, I don't get what you mean about
"set the placeholder content and make it reactive" and "use an observer"
Set discount and addditional_Services to 'reactive()'
Then on an Oberse or in use a place holder, set the placeholder content and make it reactive.
It depends but:
https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-data-before-saving
do the same calcs.
Solution
thanks for your response before..
I've decided to calculate what's in repeater in afterCreate method..