Skip to content

fix piece filter with undefined choices#5078

Merged
ETLaurent merged 3 commits intomainfrom
pro-8205-fix-filter
Sep 23, 2025
Merged

fix piece filter with undefined choices#5078
ETLaurent merged 3 commits intomainfrom
pro-8205-fix-filter

Conversation

@ETLaurent
Copy link
Copy Markdown
Contributor

@ETLaurent ETLaurent commented Sep 17, 2025

Summary

What are the specific steps to test this change?

  • Add the following piece to your project (add declare it in app.js)
export default {
  extend: '@apostrophecms/piece-type',
  fields: {
    add: {
      select: {
        label: 'Test',
        type: 'select',
        choices: [
          {
            label: '1',
            value: 'option1'
          },
          {
            label: '2',
            value: 'option2'
          }
        ]
      },
      checkboxes: {
        label: 'Tests',
        type: 'checkboxes',
        choices: [
          {
            label: 'A',
            value: 'optionA'
          },
          {
            label: 'B',
            value: 'optionB'
          },
          {
            label: 'C',
            value: 'optionC'
          }
        ]
      }
    },
    group: {
      basics: {
        fields: [ 'select', 'checkboxes' ]
      }
    }
  },
  filters: {
    add: {
      select: {
        label: 'Select Filter'
      },
      checkboxes: {
        label: 'Checkboxes Filter'
      }
    }
  }
};
  • There should be no test: api-error: Cannot read properties of undefined (reading 'match') error and the filters should work as expected:
image
  • without the fix, having undefined values in select or checkboxes breaks:
image
test: api-error: Cannot read properties of undefined (reading 'match')
 {
  module: 'test',
  type: 'api-error',
  severity: 'error',
  url: '/api/v1/test?aposMode=draft&visibility&archived=false&viewContext=manage&choices%5B0%5D=select&choices%5B1%5D=checkboxes&page=1&withPublished=1&aposLocale=en',
  path: '/api/v1/test',
  method: 'GET',
  ip: '::1',
  query: {
    aposMode: 'draft',
    visibility: null,
    archived: 'false',
    viewContext: 'manage',
    choices: [ 'select', 'checkboxes' ],
    page: '1',
    withPublished: '1',
    aposLocale: 'en'
  },
  requestId: 's2f6xxv6atu0r5qz1xtkat2n',
  name: 'error',
  status: 500,
  # ...
}

What kind of change does this PR introduce?

(Check at least one)

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Build-related changes
  • Other

Make sure the PR fulfills these requirements:

  • It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • The changelog is updated
  • Related documentation has been updated
  • Related tests have been updated: https://github.com/apostrophecms/testbed/pull/384

If adding a new feature without an already open issue, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

@linear
Copy link
Copy Markdown

linear Bot commented Sep 17, 2025

@ETLaurent ETLaurent marked this pull request as ready for review September 22, 2025 11:45
@ETLaurent ETLaurent requested a review from BoDonkey September 22, 2025 11:45
@ETLaurent ETLaurent changed the title fix filter with undefined choices fix piece filter with undefined choices Sep 22, 2025
@ETLaurent ETLaurent merged commit 0ee8672 into main Sep 23, 2025
9 checks passed
@ETLaurent ETLaurent deleted the pro-8205-fix-filter branch September 23, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants