skip to Main Content

How can I make ‘price’ to be recognized as a member of the form?

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Wizard::make([
                    WizardStep::make('First Step')
                        ->schema([
                            TextInput::make('title')->required(),
                             FormsComponentsActions::make([
                                Action::make('Custom Modal')
                                    ->button()
                                    ->form([
                                        TextInput::make('price')->prefix('$')->required(),
                                    ])
                        ]),
                    WizardStep::make('Second Step')
                        ->schema([
                                //...
                        ]),
                ]),
            ]);
    }

when I submit the form it passes this error:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘price’ cannot be null.

Generally it doesn’t work for every column that I put in modal.

2

Answers


  1. Chosen as BEST ANSWER

    After testing a lot of ways, Now this is the answer:

    //....
    WizardStep::make('First Step')
        ->schema([
            TextInput::make('title')->required(),
            Hidden::make('price'),
            FormsComponentsActions::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']);
                    }),
            ]),
    
        ]),
    //....
    

  2. I’ve tried to discover the problem. You can try my code out, 100 percent I’m sure.

    //....
    WizardStep::make('First Step')
        ->schema([
            TextInput::make('title')->required(),
            Hidden::make('price'),
            FormsComponentsActions::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']);
                    }),
            ]),
    
        ]),
    //....
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search