Issue #2176✓ SolvedOpened July 31, 2019by yucomds2 reactions

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

快速解答by pouyamiralayi2

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.

Read full answer below ↓

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)

👍 Most helpfulpouyamiralayiAugust 3, 2019

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, 2019

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.