Form builder nested fields rules
Created 8 years ago by hugogilmarHi,
I'm working on a module that handles nested attributes (user has one profile). How can I define nested form fields on the form builder?
See this example:
protected $fields = [
"email" => [
"label" => "my.module.user_account::field.email.label",
"placeholder" => "my.module.user_account::field.email.placeholder",
"instructions" => "my.module.user_account::field.email.instructions",
"type" => "anomaly.field_type.email",
"required" => true,
"rules" => [
"email" => "required|email|max:255"
],
],
"profile[first_name]" => [
"label" => "my.module.user_account::field.first_name.label",
"placeholder" => "my.module.user_account::field.first_name.placeholder",
"instructions" => "my.module.user_account::field.first_name.instructions",
"type" => "anomaly.field_type.text",
"required" => true,
"rules" => [
"profile.*.first_name" => "required|min:4|max:255"
],
],
];
I there an example how to handle those cases?.
Thanks.
Sounds like you need to use multi form builders.
Form A is a multi - and you add to it form B and C which a standard builders. Your multiple one should extend 'MultipleFormBuilder'.
Pages, posts and files module for example use multiple form builders.