Issue #1509Opened October 12, 2018by Deepak8131 reactions

How to disable undo button

Question

Hi @artf,

Hope you are doing well with grapesjs.

Can you please let us know how to disable the undo button when no data present in undo manager and vice-versa.I have check all new events but unable to find the undo active/disactive event.can you help us.

Thanks in advance

Answers (3)

chrisrobbinsMay 8, 20190 reactions

@artf If the undo event needs to be triggered to present it's data, then how can we render or disable the undo/redo btns? Out of the box the Undo/Redo buttons will clear out an entire template if the undo/redo event hasn't tracked anything. I am trying to conditionally render the undo/redo buttons based on there being anything to undo/redo. I am having trouble with the general event "Update". The Update event never seems to be triggered. Can you provide a little more context?

this.editor.on('update', () => {
      const pnm = this.editor.Panels;
      const um = this.editor.UndoManager;
      const optsPanel = pnm.getPanel('options');
      if (um.hasUndo().length > 0) {
        optsPanel.get('buttons').add({
          id: 'undo',
          className: 'fa fa-undo',
          command: 'undo',
          attributes: { title: 'undo' },
        });
      }
    });
artfMay 11, 20190 reactions

If the undo event needs to be triggered to present it's data, then how can we render or disable the undo/redo btns?

??? You can use the Undo Manager APIs wherever you want, I didn't say you can use it only after undo/redo events.

The Update event never seems to be triggered

The update event was added in https://github.com/artf/grapesjs/releases/tag/v0.14.55

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.