2

I've following code in Form.php

$chooser = $this->_layout->createBlock('\Magento\Catalog\Block\Adminhtml\Product\Widget\Chooser');
        //var_dump(get_class_methods($chooser));

        $configChooser = [
            'button' => [
                'open' => __('Select Products'),
                'type' => '\Magento\Catalog\Block\Adminhtml\Product\Widget\Chooser',
            ]
        ];
        $chooser->setConfig($configChooser)
            ->setFieldsetId($fieldset->getId())
            ->prepareElementHtml($productChooser);

When I click on Select Products button I'm getting the following error

widget.js:683 Uncaught TypeError: Cannot read property 'value' of null
    at getElementValue (widget.js:683)
    at g.choose (widget.js:620)
    at HTMLButtonElement.onclick ((index):303)

any idea what could be wrong? enter image description here

Kaushal Suthar
  • 3,227
  • 5
  • 31
  • 57

1 Answers1

3

I've resolved the issue by myself.

Above code is fine, In starting of my form code I've added

$form->setHtmlIdPrefix('xyzplan_');

Due to the above line, Widget.js file was not able to find the value of the element and throwing an error.

So I've removed it and it's now working fine.

Kaushal Suthar
  • 3,227
  • 5
  • 31
  • 57