Skip to content

Commit

Permalink
fix(form): 修复 disabled 关联子组件收集问题 (jd-opensource#2958)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu authored Mar 11, 2024
1 parent eb9a27f commit 27bc52d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/packages/__VUE/form/common.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { computed } from 'vue';
import { useParent } from '@/packages/utils';
import { FORM_KEY } from './types';
import type { ComputedRef, Ref } from 'vue';

export const FORM_KEY = Symbol('nut-form');
export const FORM_DISABLED_KEY = Symbol('nut-form-disabled');

export const useFormDisabled = (disabled: Ref<boolean>): ComputedRef<boolean> => {
const { parent } = useParent(FORM_KEY);
const { parent } = useParent(FORM_DISABLED_KEY);
return computed(() => disabled.value || parent?.props?.disabled || false);
};
5 changes: 4 additions & 1 deletion src/packages/__VUE/form/form.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { reactive, computed, provide, watch } from 'vue';
import { useChildren, getPropByPath, isPromise } from '@/packages/utils';
import NutCellGroup from '../cellgroup/index.taro.vue';
import type { FormErrorMessage, FormLabelPosition, FormRule, FormRules, FormStarPosition, FormItemRule } from './types';
import { FORM_KEY } from './types';
import { FORM_KEY, FORM_DISABLED_KEY } from './common';
defineOptions({
name: 'NutForm'
Expand All @@ -37,6 +37,9 @@ const emit = defineEmits(['validate']);
const { children, linkChildren } = useChildren(FORM_KEY);
linkChildren({ props });
const { linkChildren: linkChildren2 } = useChildren(FORM_DISABLED_KEY);
linkChildren2({ props });
const formErrorTip = computed(() => reactive<any>({}));
provide('formErrorTip', formErrorTip);
Expand Down
6 changes: 5 additions & 1 deletion src/packages/__VUE/form/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { reactive, computed, provide, watch } from 'vue';
import { useChildren, getPropByPath, isPromise } from '@/packages/utils';
import NutCellGroup from '../cellgroup/index.vue';
import type { FormErrorMessage, FormLabelPosition, FormRule, FormRules, FormStarPosition, FormItemRule } from './types';
import { FORM_KEY } from './types';
import { FORM_KEY, FORM_DISABLED_KEY } from './common';
defineOptions({
name: 'NutForm'
Expand All @@ -37,6 +37,9 @@ const emit = defineEmits(['validate']);
const { children, linkChildren } = useChildren(FORM_KEY);
linkChildren({ props });
const { linkChildren: linkChildren2 } = useChildren(FORM_DISABLED_KEY);
linkChildren2({ props });
const formErrorTip = computed(() => reactive<any>({}));
provide('formErrorTip', formErrorTip);
Expand Down Expand Up @@ -144,6 +147,7 @@ const validate = (customProp = '') => {
return new Promise((resolve, reject) => {
try {
const task = getTaskFromChildren();
console.log('task', task);
const errors = task.map((item) => {
if (customProp && customProp !== item.prop) {
Expand Down
2 changes: 0 additions & 2 deletions src/packages/__VUE/form/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const FORM_KEY = Symbol('nut-form');

export interface FormItemRuleWithoutValidator {
[key: string]: any;
regex?: RegExp;
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/formitem/form-item.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { pxCheck } from '@/packages/utils/pxCheck';
import { computed, inject, CSSProperties } from 'vue';
import type { FormItemRule, FormLabelPosition, FormStarPosition } from '../form/types';
import NutCell from '../cell/index.taro.vue';
import { FORM_KEY } from '../form/types';
import { FORM_KEY } from '../form/common';
import { useParent } from '@/packages/utils';
defineOptions({
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/formitem/form-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { pxCheck } from '@/packages/utils/pxCheck';
import { computed, inject, CSSProperties } from 'vue';
import type { FormItemRule, FormLabelPosition, FormStarPosition } from '../form/types';
import NutCell from '../cell/index.vue';
import { FORM_KEY } from '../form/types';
import { FORM_KEY } from '../form/common';
import { useParent } from '@/packages/utils';
defineOptions({
Expand Down

0 comments on commit 27bc52d

Please sign in to comment.