groupFields
groupFields(string|array $displayAs[, array $fields])
Group fields to show them as tabs in the form. The display of the tabs will look similar to the below screenshot:
For example:
$crud->groupFields("PersonalInfo", ['first_name', 'last_name', 'email']);
$crud->groupFields("Address", ['address', 'city', 'state', 'zip_code']);
$crud->groupFields("Other", ['phone', 'notes']);
or you can group them all at once:
$crud->groupFields([
'Personal Info' => ['first_name', 'last_name', 'email'],
'Address' => ['address', 'city', 'state', 'zip_code'],
'Other' => ['phone', 'notes']
]);
The keys of the array are displaying the tab names. The values are arrays of field names that will be grouped under each tab.
Notice: Keep in mind that if you decide to group the fields in tabs, fields that are not in the list
they won't be displayed in the form. For example this is not combinable with unsetFields
or setFields
method.
You can find a fully working example below:
$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
$crud->setRead();
$crud->groupFields([
'Personal Info' => ['customerName', 'contactLastName', 'contactFirstName'],
'Address' => ['addressLine1', 'addressLine2', 'city', 'state', 'postalCode', 'country'],
'Other' => ['salesRepEmployeeNumber', 'creditLimit']
]);
$output = $crud->render();
As you will see, when you open an add/edit or read form the fields are grouped into tabs named "Personal Info", "Address", and "Other" in the form.