Commit f84cbe91 authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

馃悰 Fix the reset form bug

parent 95ee75d7
Pipeline #64866 passed with stage
in 14 seconds
......@@ -37,6 +37,7 @@
<script lang="ts">
import {usfFieldMixin, usfHandleConditional, usfDefaultTokenMixin} from '@form-plugin/mixins';
import Vue from 'vue';
import {mapActions} from 'vuex';
export default Vue.extend({
name: 'UsfText',
......@@ -79,12 +80,26 @@ export default Vue.extend({
},
mounted() {
if (this.field.defaultText) {
if (this.field.defaultText && (this.exist || this.visible)) {
this.value = this.field.defaultText;
}
},
watch: {
exist: function () {
this.field.defaultText && this.exist
? this.value = this.field.defaultText
: this.deleteValue(this.field.name);
},
visible: function () {
this.field.defaultText && this.visible
? this.value = this.field.defaultText
: this.deleteValue(this.field.name);
},
},
methods: {
...mapActions('submission', ['deleteValue']),
handleMin(): boolean | string {
const test = this.field.type === 'number'
? (!!this.value && parseFloat(this.value) >= parseFloat(this.field.min))
......
......@@ -3,6 +3,9 @@ import {SubmissionState} from './SubmissionModule';
import {RootState} from '@form-plugin/store';
export const actions: ActionTree<SubmissionState, RootState> = {
deleteValue: ({commit}: ActionContext<SubmissionState, RootState>, key: string): void => {
commit('DELETE_VALUE', key);
},
/**
* Delete all values saved in the store when user uses the form in the renderer.
*
......@@ -23,4 +26,4 @@ export const actions: ActionTree<SubmissionState, RootState> = {
updateValue: ({commit}: ActionContext<SubmissionState, RootState>, payload: { key: string, value: any }): void => {
commit('UPDATE_VALUE', payload);
},
}
};
......@@ -3,6 +3,9 @@ import {SubmissionState} from './SubmissionModule';
import {MutationTree} from 'vuex';
export const mutations: MutationTree<SubmissionState> = {
DELETE_VALUE: (state: SubmissionState, key: string) => {
delete state[key];
},
/**
* @param {SubmissionState} state
*/
......@@ -15,8 +18,8 @@ export const mutations: MutationTree<SubmissionState> = {
*/
UPDATE: (state: SubmissionState, payload: { [key: string]: any }): void => {
Object.entries(payload).forEach(([key, value]) => {
Vue.set(state, key, value)
})
Vue.set(state, key, value);
});
},
/**
* Update one value with an object.
......@@ -28,4 +31,4 @@ export const mutations: MutationTree<SubmissionState> = {
UPDATE_VALUE: (state: SubmissionState, {key, value}: { key: string, value: any }): void => {
Vue.set(state, key, value);
},
}
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment