diff --git a/.changeset/thirty-grapes-laugh.md b/.changeset/thirty-grapes-laugh.md new file mode 100644 index 00000000000..e488ce24221 --- /dev/null +++ b/.changeset/thirty-grapes-laugh.md @@ -0,0 +1,5 @@ +--- +'@keystone-6/core': patch +--- + +Fix `in` and `not_in` filter views for `integer`, `bigInt`, `decimal` and `float` fields diff --git a/packages/core/src/fields/types/bigInt/views/index.tsx b/packages/core/src/fields/types/bigInt/views/index.tsx index 76dbae0db50..13c8d266205 100644 --- a/packages/core/src/fields/types/bigInt/views/index.tsx +++ b/packages/core/src/fields/types/bigInt/views/index.tsx @@ -227,19 +227,18 @@ export const controller = ( validate: value => validate(value, validation, config.label, hasAutoIncrementDefault) === undefined, filter: { - Filter(props) { + Filter({ autoFocus, type, onChange, value }) { return ( { - props.onChange(event.target.value.replace(/[^\d,\s-]/g, '')); + if (type === 'in' || type === 'not_in') { + onChange(event.target.value.replace(/[^\d,\s-]/g, '')); + return; + } + onChange(event.target.value.replace(/[^\d\s-]/g, '')); }} - value={props.value} - autoFocus={props.autoFocus} + value={value} + autoFocus={autoFocus} /> ); }, @@ -248,8 +247,8 @@ export const controller = ( const valueWithoutWhitespace = value.replace(/\s/g, ''); const parsed = type === 'in' || type === 'not_in' - ? valueWithoutWhitespace.split(',').map(x => BigInt(x)) - : BigInt(valueWithoutWhitespace); + ? valueWithoutWhitespace.split(',') + : valueWithoutWhitespace; if (type === 'not') { return { [config.path]: { not: { equals: parsed } } }; } diff --git a/packages/core/src/fields/types/decimal/views/index.tsx b/packages/core/src/fields/types/decimal/views/index.tsx index 5ff1b361fef..012fd186b3e 100644 --- a/packages/core/src/fields/types/decimal/views/index.tsx +++ b/packages/core/src/fields/types/decimal/views/index.tsx @@ -197,14 +197,19 @@ export const controller = ( }), validate: val => validate(val, validation, config.label) === undefined, filter: { - Filter(props) { + Filter({ autoFocus, type, onChange, value }) { return ( { - props.onChange(event.target.value.replace(/[^\d\.,\s-]/g, '')); + if (type === 'in' || type === 'not_in') { + onChange(event.target.value.replace(/[^\d,\s-]/g, '')); + return; + } + + onChange(event.target.value.replace(/[^\d\s-]/g, '')); }} - value={props.value} - autoFocus={props.autoFocus} + value={value} + autoFocus={autoFocus} /> ); }, diff --git a/packages/core/src/fields/types/float/views/index.tsx b/packages/core/src/fields/types/float/views/index.tsx index b2231102dbd..d61a16bd689 100644 --- a/packages/core/src/fields/types/float/views/index.tsx +++ b/packages/core/src/fields/types/float/views/index.tsx @@ -194,14 +194,18 @@ export const controller = ( serialize: value => ({ [config.path]: value.value }), validate: value => validate(value, config.fieldMeta.validation, config.label) === undefined, filter: { - Filter(props) { + Filter({ autoFocus, type, onChange, value }) { return ( { - props.onChange(event.target.value.replace(/[^\d\.,\s-]/g, '')); + if (type === 'in' || type === 'not_in') { + onChange(event.target.value.replace(/[^\d\.,\s-]/g, '')); + return; + } + onChange(event.target.value.replace(/[^\d\.\s-]/g, '')); }} - value={props.value} - autoFocus={props.autoFocus} + value={value} + autoFocus={autoFocus} /> ); }, diff --git a/packages/core/src/fields/types/integer/views/index.tsx b/packages/core/src/fields/types/integer/views/index.tsx index 2066c357125..adb795c59ee 100644 --- a/packages/core/src/fields/types/integer/views/index.tsx +++ b/packages/core/src/fields/types/integer/views/index.tsx @@ -207,19 +207,20 @@ export const controller = ( config.fieldMeta.defaultValue === 'autoincrement' ) === undefined, filter: { - Filter(props) { + Filter({ autoFocus, type, onChange, value }) { return ( { - props.onChange(event.target.value.replace(/[^\d,\s-]/g, '')); + if (type === 'in' || type === 'not_in') { + onChange(event.target.value.replace(/[^\d,\s-]/g, '')); + return; + } + + onChange(event.target.value.replace(/[^\d\s-]/g, '')); }} - value={props.value} - autoFocus={props.autoFocus} + value={value} + autoFocus={autoFocus} /> ); },