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']]


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

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

        ['name' => 'address', 'label' => __('Address'), 'title' => __('Address')]

        ['name' => 'phone', 'label' => __('Phone'), 'title' => __('Phone')]


    return parent::_prepareForm();


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.