I have created a custom form in magento2 admin via below code and it's working fine, but my form is too long, so I want to set two or more fields in one row And can divide fields in multiple tabs, Just like in Product edit form in admin. Here is my code-
protected function _prepareForm()
{
$model = $this->_coreRegistry->registry('booking_address');
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
);
$form->setHtmlIdPrefix('address_');
$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('General Information'), 'class' => 'fieldset-wide']
);
if ($model->getId()) {
$fieldset->addField('address_id', 'hidden', ['name' => 'address_id']);
}
$fieldset->addField(
'plz',
'text',
['name' => 'plz', 'label' => __('PLZ'), 'title' => __('PLZ'), 'required' => true]
);
$fieldset->addField(
'street',
'text',
['name' => 'street', 'label' => __('Street'), 'title' => __('Street'), 'required' => true]
);
$fieldset->addField(
'latitude',
'text',
['name' => 'latitude', 'label' => __('Latitude'), 'title' => __('Latitude'), 'required' => true]
);
$fieldset->addField(
'longitude',
'text',
['name' => 'longitude', 'label' => __('Longitude'), 'title' => __('Longitude'), 'required' => true]
);
$fieldset->addField(
'code',
'text',
['name' => 'code', 'label' => __('Code'), 'title' => __('Code'), 'required' => false]
);
//=START=========Want to show these fields in new tab and two in each row==============
$fieldset->addField(
'sunday',
'multiselect',
['name' => 'sunday', 'label' => __('Sunday'), 'values' => $this->getLocationTimes()]
);
$model->setData('sunday', $sunday);
$fieldset->addField(
'monday',
'multiselect',
['name' => 'monday', 'label' => __('Monday'), 'values' => $this->getLocationTimes()]
);
$model->setData('monday', $monday);
$fieldset->addField(
'tuesday',
'multiselect',
['name' => 'tuesday', 'label' => __('Tuesday'), 'values' => $this->getLocationTimes()]
);
$model->setData('tuesday', $tuesday);
$fieldset->addField(
'wednesday',
'multiselect',
['name' => 'wednesday', 'label' => __('Wednesday'), 'values' => $this->getLocationTimes()]
);
$model->setData('wednesday', $wednesday);
$fieldset->addField(
'thrusday',
'multiselect',
['name' => 'thrusday', 'label' => __('Thrusday'), 'values' => $this->getLocationTimes()]
);
$model->setData('thrusday', $thrusday);
$fieldset->addField(
'friday',
'multiselect',
['name' => 'friday', 'label' => __('Friday'), 'values' => $this->getLocationTimes()]
);
$model->setData('friday', $friday);
$fieldset->addField(
'saturday',
'multiselect',
['name' => 'saturday', 'label' => __('Saturday'), 'values' => $this->getLocationTimes()]
);
$model->setData('saturday', $saturday);
//==END========Want to show these fields in new tab and two in each row==============
$form->setValues($model->getData());
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
Please let me know how I can do this.
Thanks