Issue #2176Opened July 31, 2019by yucomds2 reactions

modal close : Uncaught TypeError: Cannot read property 'length' of undefined at V (cash.js:702)

Question

Hi,

I've this code to display a modal when I click on my custom button.

const commands = editor.Commands;
commands.add('salva-template-command', {
    run: function (editor, sender, options) {

        testo = editor.runCommand('gjs-get-inlined-html');

        var modalTitle = 'My Title';
        var modalContent = '<h1> my content</h1>';

        const modal = editor.Modal;

        modal.setTitle(modalTitle);
        modal.setContent(modalContent);
        modal.open()
        modal.onceClose(() => this.stopCommand());

    },
    stop: function (editor) {
        editor.Modal.close();
    }
})
panelManager.addButton('commands', {
    id: 'btnSaveAsTemplate',
    className: 'fa fa-th-large',
    command: 'salva-template-command',
    attributes: { title: 'My titile' },
});  

At first click, the modal appears correctly. Then I close it. Now, if I click it again I've this error in console:

immagine

I'm able to show it again only if I click for another time the custom button.

I've already followed the instruction provided here --> https://grapesjs.com/docs/modules/Commands.html#stateful-commands but I'm not able to figure it out.

My GrapeJS version is : "0.14.62" (latest). I'm facing the issue with my local copy. Tested on Firefox (latest) and Chorme (latest) on Ubuntu 16.04 LTS.

Thanks in advance!

Answers (2)

pouyamiralayiAugust 3, 20192 reactions

Hello there! I think the problem is not your modal, but it is the first command you are running: testo = editor.runCommand('gjs-get-inlined-html'); you must stop it as well: stop: function (editor) { editor.Modal.close(); editor.stopCommand('gjs-get-inlined-html') } cheers.

yucomdsAugust 5, 20190 reactions

Thanks @pouyamiralayi !

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.