|
|
@@ -67,7 +67,7 @@ Formulaire générique
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import {computed, ComputedRef, defineComponent, toRefs, ToRefs, useContext} from '@nuxtjs/composition-api'
|
|
|
+import {computed, ComputedRef, defineComponent, ref, Ref, toRefs, ToRefs, useContext} from '@nuxtjs/composition-api'
|
|
|
import {Query} from '@vuex-orm/core'
|
|
|
import {repositoryHelper} from '~/services/store/repository'
|
|
|
import {queryHelper} from '~/services/store/query'
|
|
|
@@ -109,6 +109,7 @@ export default defineComponent({
|
|
|
const nextStepFactory = new UseNextStepFactory()
|
|
|
const {id, query}: ToRefs = toRefs(props)
|
|
|
const page = new Page(store)
|
|
|
+ const form:Ref<any> = ref(null)
|
|
|
|
|
|
const entry: ComputedRef<AnyJson> = computed(() => {
|
|
|
return queryHelper.getFlattenEntry(query.value, id.value)
|
|
|
@@ -120,33 +121,37 @@ export default defineComponent({
|
|
|
}
|
|
|
|
|
|
const submit = async (next: string|null = null) => {
|
|
|
- markFormAsNotDirty()
|
|
|
-
|
|
|
- try {
|
|
|
- const response = await $dataPersister.invoke({
|
|
|
- type: QUERY_TYPE.MODEL,
|
|
|
- model: props.model,
|
|
|
- id: store.state.form.formStatus === FORM_STATUS.EDIT ? id.value : null,
|
|
|
- idTemp: store.state.form.formStatus === FORM_STATUS.CREATE ? id.value : null,
|
|
|
- query: props.query
|
|
|
- })
|
|
|
-
|
|
|
- page.addAlerts(TYPE_ALERT.SUCCESS, [i18n.t('saveSuccess') as string])
|
|
|
- nextStep(next, response.data)
|
|
|
- } catch (error) {
|
|
|
- if (error.response.status === 422) {
|
|
|
- if(error.response.data['violations']){
|
|
|
- const violations:Array<string> = []
|
|
|
- const fields:Array<string> = []
|
|
|
- for(const violation of error.response.data['violations']){
|
|
|
- violations.push(i18n.t(violation['message']) as string)
|
|
|
- fields.push(violation['propertyPath'])
|
|
|
+ if(form.value.validate()){
|
|
|
+ markFormAsNotDirty()
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await $dataPersister.invoke({
|
|
|
+ type: QUERY_TYPE.MODEL,
|
|
|
+ model: props.model,
|
|
|
+ id: store.state.form.formStatus === FORM_STATUS.EDIT ? id.value : null,
|
|
|
+ idTemp: store.state.form.formStatus === FORM_STATUS.CREATE ? id.value : null,
|
|
|
+ query: props.query
|
|
|
+ })
|
|
|
+
|
|
|
+ page.addAlerts(TYPE_ALERT.SUCCESS, [i18n.t('saveSuccess') as string])
|
|
|
+ nextStep(next, response.data)
|
|
|
+ } catch (error) {
|
|
|
+ if (error.response.status === 422) {
|
|
|
+ if(error.response.data['violations']){
|
|
|
+ const violations:Array<string> = []
|
|
|
+ const fields:Array<string> = []
|
|
|
+ for(const violation of error.response.data['violations']){
|
|
|
+ violations.push(i18n.t(violation['message']) as string)
|
|
|
+ fields.push(violation['propertyPath'])
|
|
|
+ }
|
|
|
+
|
|
|
+ new Form(store).addViolations(fields)
|
|
|
+ page.addAlerts(TYPE_ALERT.ALERT, violations)
|
|
|
}
|
|
|
-
|
|
|
- new Form(store).addViolations(fields)
|
|
|
- page.addAlerts(TYPE_ALERT.ALERT, violations)
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ page.addAlerts(TYPE_ALERT.ALERT, [i18n.t('invalide_form') as string])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -187,6 +192,7 @@ export default defineComponent({
|
|
|
})
|
|
|
|
|
|
return {
|
|
|
+ form,
|
|
|
submit,
|
|
|
updateRepository,
|
|
|
readonly,
|