Skip to content

Multiselect: better failure handling for options from API #2330

@nilshoerrmann

Description

@nilshoerrmann

Describe the bug
We've got a multiselect field that fetches its options via an API call. This stopped working.

To Reproduce
This is our field definition:

years:
  type: multiselect
  label: Zeitraum
  sort: true
  options: api
  api:
    url: '{{ kirby.url }}/hananils/years'
    fetch: years
  translate: false

If called directly, the API route returns this JSON:

{"years":{"2019":"2019","2018":"2018","2017":"2017","2016":"2016","2015":"2015","2014":"2014","2013":"2013","2012":"2012","2011":"2011","2010":"2010","2009":"2009","2008":"2008"}}

This is the underlying route in our config:

    'routes' => [
        [
            'pattern' => 'hananils/years',
            'method' => 'GET',
            'action' => function () {
                $years = [];
                $year = date('Y');
                $start = 2008;

                while ($year >= $start) {
                    $years[$year] = (string) $year;
                    $year--;
                };

                return \Kirby\Http\Response::json(['years' => $years]);
            }
        ]
    ]

Hard-coding the URL (without the kirby.url part) doesn't change anything. This worked in earlier versions.

Expected behavior
The provided years should be shown as option when using the field.

Kirby Version
3.3.1 but I don't think it's a regression in this specific version.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions