keystone icon indicating copy to clipboard operation
keystone copied to clipboard

WhereInput filter for multiselect field

Open remihuigen opened this issue 1 year ago • 1 comments

First off: Not sure if this is a bug or a feature request

When using a multiselect field, this field cant be used as part of a WHERE filter.

// Example usage
export default list({
  // list config
  fields: {
     stage: multiselect({
      label: "Relevant in fase",
      db: { map: 'stage' },
      type: 'string',
      options: stageOptions,
      defaultValue: ['orientatie'],
      ui: {
        itemView: {
          fieldPosition: 'sidebar'
        },
        listView: {
          fieldMode: () => 'read',
        },
      },
      hooks: {
        validateInput: ({operation, resolvedData, inputData, fieldKey, addValidationError}) => {
          if (operation === 'create' && !resolvedData[fieldKey]?.length) addValidationError('Een item moet ten minste één relevante fase hebben')
          else if (operation === 'update' && inputData[fieldKey] && !inputData[fieldKey].length) addValidationError('Een item moet ten minste één relevante fase hebben')
        }
      }
    })
  }
})

I expected to be able to write queries with filters for this field. Such as

query {
  pages(where: { stage: { some: { equals: "orientatie" }}}) {
    id
  }
}

But this gives an error Field "stage" is not defined by type "PageWhereInput".

I case this is not a bug: is such a feature going to be implemented any time soon? Because otherwise I'll need to look for another solution...

remihuigen avatar Feb 22 '24 14:02 remihuigen

you can implement your own multi select field without using JSON, that way it is text field for storage and select field for display

gautamsi avatar Feb 23 '24 21:02 gautamsi