1

I want to display a review form in the modal popup on the click of a button. However, the code gives this error

Uncaught TypeError: No method named "openModal"

I am using bootstrap.bundle.js in my application. If I remove that the popup is displayed without any error message.

Code I am using:

<div>
 <a href="#" id="click-me">Click Me</a>
</div>
<div id="popup-modal" style="display:none;">
 <?php echo $this->getLayout()->createBlock("Magento\Review\Block\Form")->setTemplate("Magento_Review::form.phtml")->toHtml(); ?>
</div>
<script>
 require(
 [
 'jquery',
 'Magento_Ui/js/modal/modal'
 ],
 function(
 ,ドル
 modal
 ) {
 var options = {
 type: 'popup',
 responsive: true,
 innerScroll: true,
 title: 'popup modal title',
 buttons: [{
 text: $.mage.__('Continue'),
 class: '',
 click: function () {
 this.closeModal();
 }
 }]
 };
 var popup = modal(options, $('#popup-modal'));
 $("#click-me").on('click', function () {
 $("#popup-modal").modal("openModal");
 });
 }
 );
</script>
asked Oct 30, 2019 at 7:09
6
  • Are you using this code in phtml file? Commented Oct 30, 2019 at 7:30
  • It is working correctly in frontend. I have used this code in list.phtml and review form opens correctly. Commented Oct 30, 2019 at 7:31
  • Have you tried $("#popup-modal").modal(); instead of $("#popup-modal").modal("openModal");? Commented Oct 30, 2019 at 8:08
  • Yes tried, but no luck. The problem here is because of bootstrap. Not sure why bootstrap is causing issue. Commented Oct 30, 2019 at 9:20
  • @aravind can u share the code. I am also adding the code in list.phtml. Commented Oct 30, 2019 at 9:20

1 Answer 1

4

I have also faced same problem. Its due to merging the modal.js in the bundle.js files

In magento 2 we can exclude the modal.js file from bundling by placing the exclude code in

/design/frontend/<--Magento-->/<--Luma-->/etc/view.xml

<exclude>
 ....
 <item type="file">Lib::mage/bootstrap.js</item> <!-- for excluding bootstrap-->
 <item type="file">Lib::Magento_Ui/js/modal/modal.min.js</item><!-- for excluding modal-->
 ....
</exclude>
answered Nov 13, 2019 at 10:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.