I want to add product chooser field like this
I am using this code but its not working anyone please help me.
helper = $helper; $this->_allProducts = $allProducts; $this->_systemStore = $systemStore; $this->_productloader = $_productloader; $this->timezone = $timezone; parent::__construct($context, $registry, $formFactory, $data); } /** * @return Main * @throws \Magento\Framework\Exception\LocalizedException * @throws Exception */ protected function _prepareForm() { $model = $this->_coreRegistry->registry('lofauction_product'); $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $form = $this->_formFactory->create(); //$form->setUseContainer(true); $fieldset = $form->addFieldset( 'options_fieldset', ['legend' => __('Product Information'), 'class' => 'fieldset-wide fieldset-widget-options'] ); if ($model->getId()) { $fieldset->addField('auction_entity_id', 'hidden', ['name' => 'auction_entity_id']); } if (!$model->getProductId()) { $chooserField = $fieldset->addField( 'options_fieldset_entity_id', 'label', [ 'name' => 'product_id', 'label' => __('Product'), 'required' => true, 'class' => 'widget-option', 'note' => __("Select a product"), ] ); /*Add chooser helper for the field*/ $helperData = [ 'data' => [ 'button' => ['open' => __("Select Product...")] ] ]; // $chooserField->setValue('product/' . $model->getProductId()); // Fixes Require product. $chooserField->setValue($model->getProductId()); $helperBlock = $this->getLayout()->createBlock( 'Magento\Catalog\Block\Adminhtml\Product\Widget\Chooser', '', $helperData ); $helperBlock->setConfig($helperData) ->setFieldsetId($fieldset->getId()) ->prepareElementHtml($chooserField) ->setValue($model->getId()); } else { $fieldset->addField( 'product_id', 'note', [ 'name' => 'product_id', 'label' => __('Product'), 'title' => __('Product'), 'text' => $this->helper->getProductbyId($model->getProductId())->getName() ] ); }
Please help me.how can we add one product choose field..?