input in modal doesn't work
I defined a modal in my form, but I doesn't work, I mean when I submit the main form the create-query doesn't include the input that I put in the modal,
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'price' cannot be null.
public static function form(Form $form): Form
{
return $form
->schema([
Wizard::make([
Wizard\Step::make('First Step')
->schema([
TextInput::make('title')->required(),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
// ->icon('heroicon-m-price')
->form([
TextInput::make('price')->prefix('€')->required(),
])
->action(function (Set $set, Get $get) {
$set('price', $get('price'));
}),
]),
]),
//...
]),
]);
}public static function form(Form $form): Form
{
return $form
->schema([
Wizard::make([
Wizard\Step::make('First Step')
->schema([
TextInput::make('title')->required(),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
// ->icon('heroicon-m-price')
->form([
TextInput::make('price')->prefix('€')->required(),
])
->action(function (Set $set, Get $get) {
$set('price', $get('price'));
}),
]),
]),
//...
]),
]);
}SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'price' cannot be null.
Solution
After testing a lot of ways, Now this is the answer:
....
Wizard\Step::make('First Step')
->schema([
TextInput::make('title')->required(),
Hidden::make('price'),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
->form([
TextInput::make('price')->prefix('$')->required()
->default(
function (MyModel $record = null) {
return $record?->price;
}
),
])
->action(function (Set $set, array $data) {
$set('price', $data['price']);
}),
]),
]),
........
Wizard\Step::make('First Step')
->schema([
TextInput::make('title')->required(),
Hidden::make('price'),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
->form([
TextInput::make('price')->prefix('$')->required()
->default(
function (MyModel $record = null) {
return $record?->price;
}
),
])
->action(function (Set $set, array $data) {
$set('price', $data['price']);
}),
]),
]),
....