How to update data without pressing the Submit buttonPrevent

Hello, I will bother again. I want this code to work when you press the submit button. It works as soon as a value is entered in the field. I wonder if there is a solution? Is it possible to prevent it from updating directly without pressing the Submit button?
15 Replies
LeandroFerreira
Filament
Editing records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Mehmet K.
Mehmet K.OP2y ago
I've seen this but I'm not sure how to adapt it to my code, I can't call it as a method
awcodes
awcodes2y ago
The logic is the same in a lifecycle hook. The difference is just the data. So in the lifecycle hook you have access to $data, I think that’s the name, that you can use instead of $get
Mehmet K.
Mehmet K.OP2y ago
Now, without pressing this submit button, the stock starts to decrease, so I am having problems, I wonder if there is no chance to complete this process when I press the submit button.
awcodes
awcodes2y ago
what exactly are you trying to do?
Mehmet K.
Mehmet K.OP2y ago
Let the user enter the stock status, but when the submit button is pressed, I want this stock status to be updated when the create operation or edit operation takes place.
awcodes
awcodes2y ago
ok. so you don't need it on the field at all. you just need it in the lifecycle hooks.
Mehmet K.
Mehmet K.OP2y ago
Can you give an example, I wonder how I need to use it, how can I transfer this code there?
awcodes
awcodes2y ago
something like this:
protected function beforeSave():void
{
$data = $this->form->getState();

Log::info('deneme 2');

$productOrder = ProductOrder::find($data['product_order_id']);

if ($productOrder->amount >= $data['falling_stock']) {
$de=$productOrder->amount;
$total=$de-intval($data['falling_stock']);
$productOrder->update(['amount' => $total]);
}
}
protected function beforeSave():void
{
$data = $this->form->getState();

Log::info('deneme 2');

$productOrder = ProductOrder::find($data['product_order_id']);

if ($productOrder->amount >= $data['falling_stock']) {
$de=$productOrder->amount;
$total=$de-intval($data['falling_stock']);
$productOrder->update(['amount' => $total]);
}
}
and it'd be the same on your Create except it'd be beforeCreate(), i think.
Mehmet K.
Mehmet K.OP2y ago
I will try first thing in the morning and I will be back thank you.
awcodes
awcodes2y ago
no worries.
Mehmet K.
Mehmet K.OP2y ago
Now I had the opportunity to try it, but the form data remaining in the repeater does not come. product_order_id etc. only other fields come
Mehmet K.
Mehmet K.OP2y ago
OrdersItem appears when I pull it as a form, but I cannot access it exactly.
Mehmet K.
Mehmet K.OP2y ago
I solved 🙂
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server