diff --git a/zero.Web/App/Components/Forms/form.vue b/zero.Web/App/Components/Forms/form.vue index e1caf228..ee3dabdc 100644 --- a/zero.Web/App/Components/Forms/form.vue +++ b/zero.Web/App/Components/Forms/form.vue @@ -1,6 +1,8 @@  @@ -13,14 +15,6 @@ name: 'uiForm', props: { - submit: { - type: Function, - default: () => { } - }, - mapState: { - type: Boolean, - default: true - }, errorComponents: { type: Array, default: () => [ 'uiError' ] @@ -29,6 +23,8 @@ data: () => ({ dirty: false, + loadingState: 'default', + loadingError: null, state: 'default', errors: [], slotProps: { @@ -46,6 +42,7 @@ created() { this.slotProps.state = this.state; + this.$emit('load', this); }, methods: { @@ -72,7 +69,36 @@ } }, - // handles a promise + // loads data on creation of the form + load(promise) + { + this.loadingState = 'loading'; + + return new Promise((resolve, reject) => + { + promise + .then( + response => + { + this.loadingState = 'default'; + resolve(response); + }, + (error) => + { + this.loadingState = 'error'; + this.loadingError = error; + reject(error); + } + ) + .catch(exception => + { + this.loadingState = 'error'; + this.loadingError = error; + }); + }); + }, + + // handles a promise as result of the form submission handle(promise) { this.setState('loading'); @@ -109,7 +135,7 @@ // submits the form onSubmit(e) { - this.submit(this, e); + this.$emit('submit', this, e); }, @@ -221,4 +247,11 @@ } } } - \ No newline at end of file + + + \ No newline at end of file diff --git a/zero.Web/App/Pages/settings/user.vue b/zero.Web/App/Pages/settings/user.vue index 90a93dbc..f52ea6ac 100644 --- a/zero.Web/App/Pages/settings/user.vue +++ b/zero.Web/App/Pages/settings/user.vue @@ -1,5 +1,5 @@