Hi,
I’m currently trying to query a nested select field in a structure field. I got a solution from here.
I have set up a settings page with the following content:
categories:
type: tags
label: Kategorien
width: 1/2
menu:
type: structure
fields:
rubrik:
label: Rubrik
type: pages
multiple: false
cat:
label: Kategorie
type: multiselect
options: query
query:
fetch: page.categories.split
text: "{{ arrayItem.value }}"
value: "{{ arrayItem.value }}"
In addition, I was able to set up a route with a json response:
'pattern' => 'lesen-article-category.json',
'action' => function () {
$categories = array();
foreach (site()->draft('settings')->menu()->toStructure() as $filterCategory) {
if ($filterCategory->rubrik()->toPage()->title() == "Lesen") {
foreach ($filterCategory->cat()->split(",") as $category) {
$categories[] = $category;
}
}
}
return response::json($categories);
}
This works so far and I get an Array with the content of the multi-select field when I call the url.
On a different page I want to use the json response for a select field with the api option:
category:
label: Kategorie
type: select
required: true
options: api
api:
url: "{{ site.url }}/lesen-article-category.json"
text: "{{ item }}"
value: '"{{ item.name }}":"{{ item }}"'
Unfortunately, I then get the following error message in the panel:
Am I missing something here?