Work in progress on confirmation dialogs displayed when one navigates from a page with unsaved changes.
Optimized imports.
This commit is contained in:
parent
008fd21b51
commit
c4b78c4823
1 changed files with 21 additions and 8 deletions
|
@ -1079,7 +1079,10 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
|
||||||
proto.initForm = function(settings) {
|
proto.initForm = function(settings) {
|
||||||
const state = this.state || {};
|
const state = this.state || {};
|
||||||
state.formState = cleanFormState;
|
state.formState = cleanFormState;
|
||||||
state.formSettings = settings || {};
|
state.formSettings = {
|
||||||
|
leaveConfirmation: true,
|
||||||
|
...(settings || {})
|
||||||
|
};
|
||||||
this.state = state;
|
this.state = state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1164,11 +1167,13 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
|
||||||
|
|
||||||
const response = await axios.method(method, getUrl(url), data);
|
const response = await axios.method(method, getUrl(url), data);
|
||||||
|
|
||||||
|
if (settings.leaveConfirmation) {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
this.setState(previousState => ({
|
this.setState(previousState => ({
|
||||||
formState: previousState.formState.set('savedData', previousState.formState.get('data'))
|
formState: previousState.formState.set('savedData', previousState.formState.get('data'))
|
||||||
}), resolve);
|
}), resolve);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return response.data || true;
|
return response.data || true;
|
||||||
|
|
||||||
|
@ -1180,6 +1185,8 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
|
||||||
|
|
||||||
|
|
||||||
proto.populateFormValues = function(data) {
|
proto.populateFormValues = function(data) {
|
||||||
|
const settings = this.state.formSettings;
|
||||||
|
|
||||||
this.setState(previousState => ({
|
this.setState(previousState => ({
|
||||||
formState: previousState.formState.withMutations(mutState => {
|
formState: previousState.formState.withMutations(mutState => {
|
||||||
mutState.set('state', FormState.Ready);
|
mutState.set('state', FormState.Ready);
|
||||||
|
@ -1192,7 +1199,9 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (settings.leaveConfirmation) {
|
||||||
mutState.set('savedData', mutState.get('data'));
|
mutState.set('savedData', mutState.get('data'));
|
||||||
|
}
|
||||||
|
|
||||||
validateFormState(this, mutState);
|
validateFormState(this, mutState);
|
||||||
})
|
})
|
||||||
|
@ -1340,6 +1349,8 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
|
||||||
proto.isFormChanged = function() {
|
proto.isFormChanged = function() {
|
||||||
const settings = this.state.formSettings;
|
const settings = this.state.formSettings;
|
||||||
|
|
||||||
|
if (!settings.leaveConfirmation) return false;
|
||||||
|
|
||||||
if (settings.getPreSubmitUpdater) {
|
if (settings.getPreSubmitUpdater) {
|
||||||
// getPreSubmitUpdater is an async function. We cannot do anything async here. So to be on the safe side,
|
// getPreSubmitUpdater is an async function. We cannot do anything async here. So to be on the safe side,
|
||||||
// we simply assume that the form has been changed.
|
// we simply assume that the form has been changed.
|
||||||
|
@ -1352,6 +1363,8 @@ const withForm = createComponentMixin([], [], (TargetClass, InnerClass) => {
|
||||||
proto.isFormChangedAsync = async function() {
|
proto.isFormChangedAsync = async function() {
|
||||||
const settings = this.state.formSettings;
|
const settings = this.state.formSettings;
|
||||||
|
|
||||||
|
if (!settings.leaveConfirmation) return false;
|
||||||
|
|
||||||
if (settings.getPreSubmitUpdater) {
|
if (settings.getPreSubmitUpdater) {
|
||||||
const preSubmitUpdater = await settings.getPreSubmitUpdater();
|
const preSubmitUpdater = await settings.getPreSubmitUpdater();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue