0

I want to add dynamic input field for my custom admin form. I have found a solution :How to create a dynamic fields in admin form? but it's for system configuration and I want this option in my custom form. Here you can see I have created the form:

protected function _prepareForm()
{
    /** @var Event $model */
    $model = $this->_coreRegistry->registry('vendor_test');

    /** @var \Magento\Framework\Data\Form $form */
    $form = $this->_formFactory->create(
        ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
    );

    $form->setHtmlIdPrefix('branch_');

    $fieldset = $form->addFieldset(
        'base_fieldset',
        ['legend' => __('Branch'), 'class' => 'fieldset-wide']
    );

    if ($model->getId()) {
        $fieldset->addField('id', 'hidden', ['name' => 'id']);
    }       

    $fieldset->addField(
        'address',
        'textarea',
        ['name' => 'address', 'label' => __('Address'), 'title' => __('Address')]
    );

    $fieldset->addField(
        'phone',
        'text',
        ['name' => 'phone', 'label' => __('Phone'), 'title' => __('Phone')]
    );        

    $form->setValues($model->getData());
    $form->setUseContainer(true);
    $this->setForm($form);

    return parent::_prepareForm();
}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.