Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix: template form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
hibig committed Aug 18, 2023
1 parent 8b5d8ea commit 9b7a0c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/components/form-create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
:span="setGridItemSpan(fm, index)"
>
<a-form-item
:key="fm.name"
:field="fm.name"
:rules="fm.rules"
hide-label
Expand Down Expand Up @@ -118,6 +119,7 @@
style="width: 100%"
width="100%"
:editor-id="`${fm.name}_editorId_${index}`"
:event-handler="() => eventHandler(fm.name)"
@input="(e) => handleSelectInputChange(e, fm.type)"
>
<template v-if="fm.childCom">
Expand Down Expand Up @@ -255,6 +257,7 @@
const activeMenu = ref('');
const OTHER_SUB_GROUP = 'Other';
const triggerValidate = ref(false);
const validateState = ref(false); // if has executed validate
const activeSchemaList = computed(() => {
if (!activeMenu.value) {
Expand Down Expand Up @@ -295,6 +298,11 @@
schemaType.isUnknownType(item.type)
) {
val = json2Yaml(val);
} else if (
schemaType.isListNumber(item.type) ||
schemaType.isListString(item.type)
) {
val = val || [];
}
formData.value[item.name] = val;
});
Expand Down Expand Up @@ -362,13 +370,22 @@
};
const handleClickSubGroup = (k) => {
activeMenu.value = k;
if (validateState.value) {
setTimeout(() => {
formref.value?.validate?.();
});
}
};
const eventHandler = (filedName) => {
formref.value?.validateField?.(filedName);
};
const setSchemaList = () => {
const showIfMap = {};
activeMenu.value = '';
subGroupCache.value = {};
subGroupListCache.value = {};
triggerValidate.value = false;
validateState.value = false;
thirdGroupCache.value = {};
let list = map(props.formSchema, (o, i) => {
Expand Down Expand Up @@ -503,6 +520,7 @@
triggerValidate.value = true;
const result = await formref.value?.validate();
const validLabels = validateLabels();
validateState.value = true;
if (result) {
const errorField = get(keys(result), '0');
Expand Down
4 changes: 3 additions & 1 deletion src/components/hint-input/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
default() {
return {};
}
}
},
eventHandler: Function
});
const completeData = inject('completeData', ref(null));
const $attrs = useAttrs();
Expand Down Expand Up @@ -418,6 +419,7 @@
const runChange = () => {
emits('change', expression.value);
inputFlag.value = false;
props.eventHandler?.();
};
const handleBlur = () => {
isFocus.value = false;
Expand Down

0 comments on commit 9b7a0c1

Please sign in to comment.