Browse Source

fix: filter invalid form items #4435

pull/4459/head
tangjinzhou 3 years ago
parent
commit
5bdd6f4007
  1. 17
      components/form/FormItem.tsx
  2. 2
      v2-doc

17
components/form/FormItem.tsx

@ -1,4 +1,4 @@
import type { PropType, ExtractPropTypes, ComputedRef } from 'vue';
import { PropType, ExtractPropTypes, ComputedRef, watch } from 'vue';
import { defineComponent, computed, nextTick, ref, watchEffect, onBeforeUnmount } from 'vue';
import cloneDeep from 'lodash-es/cloneDeep';
import PropTypes from '../_util/vue-types';
@ -271,6 +271,13 @@ export default defineComponent({
clearValidate,
resetField,
});
let registered = false;
watch(
fieldName,
val => {
if (val) {
if (!registered) {
registered = true;
formContext.addField(eventKey, {
fieldValue,
fieldId,
@ -281,6 +288,14 @@ export default defineComponent({
validateRules,
rules: rulesRef,
});
}
} else {
registered = false;
formContext.removeField(eventKey);
}
},
{ immediate: true },
);
onBeforeUnmount(() => {
formContext.removeField(eventKey);
});

2
v2-doc

@ -1 +1 @@
Subproject commit fc73e64bcdf41be854c2f7a907c05b056ad652ab
Subproject commit e67d63729715291f481029fe9497f0109f328504
Loading…
Cancel
Save