Can't save form action

I can't save the value in advanced form action that give me null.
Forms\Components\TextInput::make('remaining_stock')
->disabled()
->suffixAction(
Action::make('addingNewStock')
->label('Add New Stock')
->icon('heroicon-m-plus')
->requiresConfirmation()
->form([
Forms\Components\TextInput::make('adding_stock')
->numeric()
->rules(['integer', 'min:0'])
])
->modalIcon('heroicon-m-plus')
->action(function (
Forms\Set $set, Get $get, array $data
): void {
$set(
'remaining_stock',
$get('remaining_stock') + $data['adding_stock']);
})
)
Forms\Components\TextInput::make('remaining_stock')
->disabled()
->suffixAction(
Action::make('addingNewStock')
->label('Add New Stock')
->icon('heroicon-m-plus')
->requiresConfirmation()
->form([
Forms\Components\TextInput::make('adding_stock')
->numeric()
->rules(['integer', 'min:0'])
])
->modalIcon('heroicon-m-plus')
->action(function (
Forms\Set $set, Get $get, array $data
): void {
$set(
'remaining_stock',
$get('remaining_stock') + $data['adding_stock']);
})
)
Solution:
sorry, it confused me. You were showing the edit page with the problem, now you are saying that it is working 🤷‍♂️
Jump to solution
22 Replies
LeandroFerreira
LeandroFerreira9mo ago
because it is disabled?
Shaung Bhone
Shaung BhoneOP9mo ago
I don't think so.
LeandroFerreira
LeandroFerreira9mo ago
do you mean, it is null when you submit the form?
Shaung Bhone
Shaung BhoneOP9mo ago
yes
LeandroFerreira
LeandroFerreira9mo ago
try without disabled
Shaung Bhone
Shaung BhoneOP9mo ago
It's not working
LeandroFerreira
LeandroFerreira9mo ago
is remaining_stock fillable?
Shaung Bhone
Shaung BhoneOP9mo ago
no it's not.
LeandroFerreira
LeandroFerreira9mo ago
are you trying to store a field that isn't fillable?
Shaung Bhone
Shaung BhoneOP9mo ago
I'm using Model::unguard
LeandroFerreira
LeandroFerreira9mo ago
The issue lies in the fact that remaining_stock is not being stored in the database. I recommend investigating why this data isn’t being saved. This isn't related with the action..
Shaung Bhone
Shaung BhoneOP9mo ago
No description
Shaung Bhone
Shaung BhoneOP9mo ago
->action(function (Set $set, Get $get, array $data): void {
$currentRemainingStock = $get('remaining_stock');
$additionalStock = $data['adding_stock'];
dd($set(
'remaining_stock',
$currentRemainingStock + $additionalStock
));
})
->action(function (Set $set, Get $get, array $data): void {
$currentRemainingStock = $get('remaining_stock');
$additionalStock = $data['adding_stock'];
dd($set(
'remaining_stock',
$currentRemainingStock + $additionalStock
));
})
LeandroFerreira
LeandroFerreira9mo ago
this isn't null 🤷‍♂️
Shaung Bhone
Shaung BhoneOP9mo ago
Yes action are not working
->prefixAction(
Action::make('reset')
->icon('heroicon-m-arrow-path')
->modalHeading('Are you sure?')
->modalDescription('All existing stocks will be removed')
->requiresConfirmation()
->color('danger')
->action(fn(Forms\Set $set) => $set('remaining_stock', 0)),
)
->prefixAction(
Action::make('reset')
->icon('heroicon-m-arrow-path')
->modalHeading('Are you sure?')
->modalDescription('All existing stocks will be removed')
->requiresConfirmation()
->color('danger')
->action(fn(Forms\Set $set) => $set('remaining_stock', 0)),
)
that reset button is not actually reset the database. what is happeninig? gg
LeandroFerreira
LeandroFerreira9mo ago
this action won't save the data. The button in the form will save the data
Shaung Bhone
Shaung BhoneOP9mo ago
Yes I mean The button in the form is not saving the data
Shaung Bhone
Shaung BhoneOP9mo ago
LeandroFerreira
LeandroFerreira9mo ago
because you don't have the remaining_stock input in the form
Shaung Bhone
Shaung BhoneOP9mo ago
it's working in edit state It's not working when createing new product
Solution
LeandroFerreira
LeandroFerreira9mo ago
sorry, it confused me. You were showing the edit page with the problem, now you are saying that it is working 🤷‍♂️
Shaung Bhone
Shaung BhoneOP9mo ago
Thank you for your help. Let me check it.
Want results from more Discord servers?
Add your server