From f0f6e958d9dc986b24220764c1bc4308f3c3e1a0 Mon Sep 17 00:00:00 2001 From: Adrien Date: Thu, 5 May 2022 16:57:34 +0200 Subject: [PATCH] fix(nullBoolean): filter display in query if undefined --- src/utils/listPaginatedTools.ts | 8 ++++---- vue3-example/src/components/HelloWorld.vue | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/listPaginatedTools.ts b/src/utils/listPaginatedTools.ts index ede7712..1c7ba99 100644 --- a/src/utils/listPaginatedTools.ts +++ b/src/utils/listPaginatedTools.ts @@ -32,12 +32,12 @@ const isValueDefault = (value: any, param: string, schema?: VDUSFormSchema): boo let isValueDefault: boolean = value === ""; if (schema && schema[param]) { - // We have a special case for nullBoolean because we can have null value that is not the default - if(schema[param]?.type === "nullBoolean") { - return schema[param].default === extractNullBooleanValue(value, schema[param].default) - } // if there is a defautl value we change the condition to is non equality if (typeof(schema[param].default) !== "undefined") { + // We have a special case for nullBoolean because we can have null value that is not the default + if(schema[param]?.type === "nullBoolean") { + return schema[param].default === extractNullBooleanValue(value, schema[param].default) + } // TODO default value for array need to be stringify ? if (Array.isArray(value)) { isValueDefault = isEqual(value, schema[param].default) || !value.length; diff --git a/vue3-example/src/components/HelloWorld.vue b/vue3-example/src/components/HelloWorld.vue index 2dcbd27..e4f145f 100644 --- a/vue3-example/src/components/HelloWorld.vue +++ b/vue3-example/src/components/HelloWorld.vue @@ -56,7 +56,7 @@ export default defineComponent({ // --------------------- DATA ------------------------------------ const form = ref({ search: "", - is_answered: false + is_answered: null }) const options = ref({ page: 1, @@ -66,7 +66,7 @@ export default defineComponent({ const items = ref([]) const formSchema = ref({ - is_answered: { type: "nullBoolean", default: false } + is_answered: { type: "nullBoolean" } }) // --------------------- METHODS ------------------------------------ @@ -85,7 +85,7 @@ export default defineComponent({ return respondToFilter }) } - if (typeof queryAsObject.is_answered !== "undefined") { + if (typeof queryAsObject.is_answered !== "undefined" && queryAsObject.is_answered !== null) { fakeData = fakeData.filter(data => { return data.is_answered === queryAsObject.is_answered })