F
Filament12mo ago
Azade

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,
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: ```php .... Wizard\Step::make('First Step') ->schema([...
Jump to solution
3 Replies
Andrew Wallo
Andrew Wallo12mo ago
I am not 100% sure if the way you are implementing this is correct, but try adding "live" to the TextInput like this:
Action::make('Custom Modal')
->button()
// ->icon('heroicon-m-price')
->form([
TextInput::make('price')
->live()
->prefix('€')
->required(),
])
->action(function (Set $set, Get $get) {
$set('price', $get('price'));
}),
Action::make('Custom Modal')
->button()
// ->icon('heroicon-m-price')
->form([
TextInput::make('price')
->live()
->prefix('€')
->required(),
])
->action(function (Set $set, Get $get) {
$set('price', $get('price'));
}),
I'm also not really sure why you are trying to set the state of the price with its own state.. Doesnt really make sense
Azade
AzadeOP12mo ago
@Andrew WalloThank you, but it still doesn't work, And also I wanted to say that in modal there were a big form, but I summarized it to ask my question.
Solution
Azade
Azade12mo ago
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']);
}),
]),

]),
....
Want results from more Discord servers?
Add your server