Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 32b2bae

Browse files
committed
fix(types): handle validation on submit
1 parent b5a753a commit 32b2bae

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components/dynamic-form/DynamicForm.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ export default defineComponent({
108108
});
109109
110110
const isValid = computed(() => {
111-
const control = controls?.value?.find(control => !control.valid);
112-
return control ? control.valid : true;
111+
const hasInvalidControls = controls.value.some(control => !control.valid);
112+
return !hasInvalidControls;
113113
});
114114
115115
const errors = computed(() => {
@@ -146,12 +146,12 @@ export default defineComponent({
146146
}
147147
});
148148
149-
function valueChange(changedValue) {
149+
function valueChange(changedValue: Record<string, unknown>) {
150150
Object.assign(formValues, changedValue);
151151
ctx.emit('changed', removeEmpty(formValues));
152152
}
153153
154-
function mapControls(empty?) {
154+
function mapControls(empty?: boolean) {
155155
const controlArray =
156156
Object.entries(props.form?.fields).map(
157157
([key, field]: [string, InputType]) =>
@@ -162,12 +162,14 @@ export default defineComponent({
162162
value: null,
163163
dirty: false,
164164
touched: false,
165+
valid: true,
165166
} as FormControl<InputType>)
166167
: ({
167168
...field,
168169
name: key,
169170
dirty: false,
170171
touched: false,
172+
valid: true,
171173
} as FormControl<InputType>),
172174
) || [];
173175
if (props.form.fieldOrder) {

0 commit comments

Comments
 (0)