0

I have a modal with 2 buttons that have a click function. Inside of each of these click functions is a block that's supposed to only be executed when clicked. However, the block seems to be executed before one of the buttons is clicked.

buttons: [
            {
                text: $.mage.__(`Don't Allow`),
                class: 'dontAllow',
                click: function(){
                    console.log(`I clicked Don't Allow`);
                    <?= $block->disableAdminUsage(); ?>
                    this.closeModal();
                },
            },
            {
                text: $.mage.__('Ok'),
                class: 'action',
                click: function(){
                    console.log("I clicked Ok");
                    <?= $block->enableAdminUsage(); ?>
                    this.closeModal();
                },
            }
        ],
  • Yes, because you use those in php. So when echoed it executed. What you return from enableAdminUsage and disableAdminUsage? – Sohel Rana Jul 15 at 23:34
  • @SohelRana enableAdminUsage and disableAdminUsage simply edits the value and saves it. $configModel = $this->configFactory->create(); $configModel->setDataByPath('path', 0); $configModel->save(); – michellbrito Jul 16 at 14:07
  • wrong. you should move this to controller and call ajax on click event. – Sohel Rana Jul 16 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.