From af87ad84446d6eaffb07350086ca258f522c95b4 Mon Sep 17 00:00:00 2001 From: sallerli1 Date: Mon, 27 Feb 2023 10:31:35 +0800 Subject: [PATCH] fix(pro:search): mutiple search filed validation error --- .../pro/search/src/composables/useSearchStates.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/pro/search/src/composables/useSearchStates.ts b/packages/pro/search/src/composables/useSearchStates.ts index 9adcc888b..47899b2b7 100644 --- a/packages/pro/search/src/composables/useSearchStates.ts +++ b/packages/pro/search/src/composables/useSearchStates.ts @@ -135,14 +135,22 @@ export function useSearchStates( return false } - const searchField = props.searchFields?.find(field => field.key === searchState.fieldKey) + // all valid segmentValue are not allowd to be undefined or null + // when current value isn't valid, return immediatly + if (!searchState.segmentValues.every(segmentValue => !isNil(segmentValue.value))) { + return false + } const count = dataKeyCountMap.get(searchState.fieldKey) + + // if there are more than one searchState of the same field key + // check whether mutiple searchState is allowed from the field config if (count && count > (existed ? 1 : 0)) { - return !!searchField?.multiple + return !!props.searchFields?.find(field => field.key === searchState.fieldKey)?.multiple } - return searchState.segmentValues.every(segmentValue => !isNil(segmentValue.value)) + // all validations are passed + return true } const validateSearchState = (key: VKey) => {