Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: make it possible to clear changed status after SetContents #161

Closed
MRB60 opened this issue Dec 2, 2019 · 8 comments
Closed

Comments

@MRB60
Copy link

MRB60 commented Dec 2, 2019

Again, thanks for making Suneditor!
It seems as if setContents() causes editor to assume a change to contents has been made (and save button is enabled).
It would be nice to be able to clear this changed status (and disable save button) so that contents look unedited until user edit contents (or contents is appended/changed otherwise). I would suggest a function call which can clear the changed status (not sure about history though).
Any workaround would also work out for me!

@JiHong88
Copy link
Owner

JiHong88 commented Dec 3, 2019

Hi,
That's good idea.
I'll add an argument that does not update the history stack.
Thank you.

@JiHong88
Copy link
Owner

Hi,
Updated in v2.23.0

const editor = suneditor.create(..);
editor.setContents('html');
editor.core.history.reset(); // history stack reset

Thank you.

@MRB60
Copy link
Author

MRB60 commented Dec 11, 2019

History clear works fine but setContents seem still to trigger an onChange event and the save button is still enabled (as if there is something unsaved). Anyway to avoid this? The event I can work around but would be nice if the save button could be disabled somehow.

@JiHong88
Copy link
Owner

Hi,
I fixed the issue.
Applies to the next version.
Before that, you can following method:

const editor = suneditor.create(..);
editor.setContents('html');
editor.core.history.reset(); // history stack reset
// ** disalbed save button **
editor.core.context.tool.save.disabled = true;

core.context

Thank you.

@MRB60
Copy link
Author

MRB60 commented Dec 12, 2019

Great - got it working with your workaround and by ignoring first onChange event.
Thank you.

@JiHong88
Copy link
Owner

You can declare the onChange event after setContents.

const editor = suneditor.create(..);
editor.setContents('html');
editor.core.history.reset(); // history stack reset
// ** disalbed save button **
editor.core.context.tool.save.disabled = true;
// onChange
editor.onChange = function...

@MRB60
Copy link
Author

MRB60 commented Dec 12, 2019

Yes - works great.
You have shown how I can use setContents() and still handle content as unchanged - as requested in this feature request. I close it now.
Thank you.

@MRB60 MRB60 closed this as completed Dec 12, 2019
@JiHong88
Copy link
Owner

Hi, again

The v2.23.1 version has been updated.

You can use it like this:

const editor = suneditor.create(..);
editor.setContents('html');
editor.core.history.reset(true);

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants