Undefined array key name despite having validation
Is it normal to have multiple arrays inside of mountedFormComponentActionsData for a select field with CreateOptionForm. The 500 error undefined array key 'name' has occured two times in production despite having validation in place and I couldn't quite figure out what's causing this issue.
Forms\Components\Select::make('customer_id')
->label('Select Customer')
->required()
->createOptionAction(function (FormAction $action) {
return $action
->modalHeading('Create customer')
->modalSubmitActionLabel('Create customer')
->modalWidth('lg');
})
->createOptionForm([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone')
->maxLength(255),
Forms\Components\TextInput::make('address')
->maxLength(255),
])
->createOptionUsing(function ($data) {
$customer = new Customer;
$customer->name = $data['name'];
$customer->phone = $data['phone'];
$customer->address = $data['address'];
$customer->save();
return $customer->id;
}),
Logged Request data
"mountedFormComponentActionsData" : [
[
[{"name": null, "phone": null, "address": null}, {"s": "arr"}],
[{"name": "nihal stha", "phone": null, "address": null}, {"s": "arr"}]
],
{"s": "arr"}
]
"errors":{"mountedFormComponentActionsData.0.name":["The name field is required."]},"locale":"en"}
2 Replies
Why do you use
->createOptionUsing()
instead of using the default?I remember that it was to return the $customer->id back to the select and get the newly created customer selected . The default wasn't working.
By working I mean, the customer name wasn't showing up as selected in select field and it was empty.
I removed this extra bit of code from the original message due to character limitation.