-
Notifications
You must be signed in to change notification settings - Fork 3
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
Ability to revert unsaved changes #101
Comments
Thanks for your question! mstform doesn't have direct support for this (at the moment, we could potentially add support). It's rather fundamental to its architecture that the node is kept in sync with the form itself. But you can make it work by keeping a MST snapshot of your node of the state before the form was shown, and then if the user presses cancel, apply that snapshot again. We could add support for this - make such a snapshot when form state is made, and apply it automatically to the node if the user calls a 'revert' method on the state. |
Hi @faassen, thanks for your reply. I've realized that the easiest way to reach it will be something like: const m = M.create();
const initialState = getSnapshot(m);
function save(node) {
applySnapshot(m, getSnapshot(node));
}
const form = form.state(clone(m), {
backend: {
save,
}
};
function reset() {
applySnapshot(form.node, initialState);
} I think it would be cool to have it in docs as well. |
Better late than never ;) This has been implemented in version 1.32.0, also see: https://github.com/isprojects/mstform#restore-state |
I was looking through the docs and didn't find a way to revert changes to the model.
I have a profile settings screen, which has some base editable info of a user and a "save" button.
Sometimes user can decide to dismiss editing. But any changes to the model are already in my model.
How can I decline changes or make a change to the real node just after the save have happened?
The text was updated successfully, but these errors were encountered: