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

Store doesn't seem to be updating #536

Closed
jamesgorrie opened this issue Jun 8, 2017 · 8 comments
Closed

Store doesn't seem to be updating #536

jamesgorrie opened this issue Jun 8, 2017 · 8 comments

Comments

@jamesgorrie
Copy link

When visiting the example page, if we edit the content, then run SirTrevor.getInstance().store.retrieve(); in the console, the data array has not updated.

Running the latest Chrome.

I wonder if perhaps Chrome has updated something around mutation - but either way, it has rendered the editor unusable.

Happy to help if I can - I was trying, but it's quite hard to debug.

@raffij
Copy link
Contributor

raffij commented Jun 8, 2017

Does this work?

SirTrevor.getInstance().onFormSubmit();
SirTrevor.getInstance().store.retrieve();

@jamesgorrie
Copy link
Author

Ah yes - so, am I write in assuming then that form.onSubmit the data is saved?
And ST prevents the forms default action?

And if we prevent the action, the event doesn't bubble, and the data is not saved?

@raffij
Copy link
Contributor

raffij commented Jun 8, 2017

You are correct.

At present the editor behaves like a textarea replacement so relies on the form submission to store the current state of the editor.

@jamesgorrie
Copy link
Author

Is there an event then that we can hook onto to know when the data has been saved?

@raffij
Copy link
Contributor

raffij commented Jun 8, 2017

When you call onFormSubmit() the blocks will be parsed and the data saved to the store. The function returns the number of errors that were generated and puts the toString representation in the textarea.

https://github.com/madebymany/sir-trevor-js/blob/master/src/editor.js#L240-L256

The function above is the one that would normally be called when the form is submitted as can be seen here: https://github.com/madebymany/sir-trevor-js/blob/master/src/form-events.js#L19

@jamesgorrie
Copy link
Author

Okay.
I suppose we just make sure that we attach our submit listener after ST's to ensure that has been fired (as we're guaranteed order).

@jamesgorrie
Copy link
Author

Looking at that - this means that we have to add the event listener before initialising ST?
As if we preventDefault() the event doesn't reach ST.

@raffij
Copy link
Contributor

raffij commented Jun 9, 2017

You shouldn't need to as something like this would work.

const el = document.querySelector('.sir-trevor');
const form = el.parentNode;

const editor = new SirTrevor.Editor({ el: el });

form.addEventListener('submit', function (e) {
  e.preventDefault();
  console.log(editor.store.toString(true));
});

@raffij raffij closed this as completed Feb 5, 2019
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