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)
On undo/redo events https://grapesjs.com/docs/api/editor.html#general
you can use Undo Manager APIs https://grapesjs.com/docs/api/undo_manager.html
@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' },
});
}
});
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.
Issue #1111
How to add parent class when drag element
Hi @artf, Hope you are doing fine. Please let us know how we can add the parent class of div when new element is dragged inside that div li...
Issue #1683
How to change id/class when new element drop on editor or render element with dynamic ip?
Hello @artf , Hope you are doing well. I have two questions regards dynamic blocks adding, 1) Is it possible to render the block with dynam...
Issue #1527
How to add countdown/navigation event in undo/redo
Hello @artf, How can we add any changes/events in undo/redo Manager like when we drag element like navigation or countdown. Hope for positi...
Issue #1497
Inner element content change with pop-up
Hello @artf I've make pop-up for select custom link data with image. Now all the data reflected properly but when I try to change src than...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.