Select field — Options from structure field

Dear community,

I fear I ran into my first issue with Kirby 3 … but I’m sure someone here might be able to help.

For almost an hour now I’m trying to add a select field to one of my pages in the panel. Here’s the link to the reference docs: https://getkirby.com/docs/reference/fields/select#options-from-other-fields

My code is the following …

fields:
  name-of-fields:
    label: name-of-fields
    type: structure
    fields:
      field-value-1:
        label: field-value-1
        type: text
      field-value-2:
        label: field-value-2
        type: text
      field-value-3:
        label: field-value-3
        type: text
      something:
        label: Some Thing
        type: select
        options: query
          query:
            fetch: site.find("page-im-looking-for").name-of-fields.toStructure
            text: "{{ structureItem.field-value-1 }}: {{ structureItem.field-value-2 }}"
            value: "{{ structureItem.field-value-3 }}"
        required: true

Unfortunately, the panel only lists one option in the select field … literally(!) what’s defined for text:, that means “{{ structureItem.field-value-1 }}: {{ structureItem.field-value-2 }}”

Any ideas what happens here?

I’m not quite sure I understand what are you trying to achieve.
Am I right in assuming you’re trying to populate the select field with each entry present inside a structure field stored in another page?

@manuelmoreale, that’s exactly what I’m trying to achieve.

Tested your code and everything seems to work as expected. Maybe it’s an issue with the field names?

The structure…

And the select

1 Like

First thing: You can’t use dashes in field names, can you even fill your structure field?

1 Like

I’ll leave you here the code I used to test it just in case. I used the home and the site yml to debug so you probably need to change the initial query if you want to try it on your specific page

fields:
    
    testfield :
        label  : Debug
        type   : structure
        fields :
            debone:
                label : Debug Value One
                type  : text
            debtwo:
                label : Debug Value Two
                type  : text
            debthree:
                label : Debug Value Three
                type  : text

and

fields:
    debugselect:
        label    : Debug Field
        type     : select
        required : true
        options  : query
        query:
            fetch: site.homePage.testfield.toStructure
            text: "{{ structureItem.debone }}: {{ structureItem.debtwo }}"
            value: "{{ structureItem.debthree }}"
1 Like

Excuse me, the dashes in field names were just examples. Though, good to know, won’t use it again here.

I don’t see any differences comparing @manuelmoreale’s code with mine above … maybe there’s a problem with the site.find("pagename").pagefields.toStructure line, maybe "pagename" is not found? Even though that’s the filename content/pagename/pagename.txt and also the title in site/blueprints/pages/pagename.yml … I don’t quite get it.

Not quite sure what’s the issue sadly. The code I tried seems to work as expected so it’s probably something related to your specific setup.

Maybe a conflict with one of the keys?

maybe “pagename” is not found?

If you said you only see one of the values from the structure field that means the page is correctly fetched so I don’t think that’s the issue.

Probably a stupid question but you never know: does the structure filed contain more than one set of values?

There’s thirty sets of values, and each set has three values.

What are you expecting to appear as select options? All three values of the three field defined within the structure field? That won’t work.

The TEXT in the select field should consist of the first two value, exactly as in @manuelmoreale’s screenshot above. I also tried with only one value, did not work either.

I just tested this an worked for me, even with fetch: site.find('home').testfield.toStructure

Can you post the exact code you are using and not one changed for the forum?
Because maybe there’s something specifically tied to your case and we can’t see it.

Because the general case seems to work as expected.

Sure, sorry for obfuscating it … just wanted to keep it general and easy.

content/1_semesters/semesters.txt

Title: semesters

----

Semesters:

-
  semester: Sommersemester 2018
  topic: insert topic here
  id: 2018-ss
-
  semester: Wintersemester 2017
  topic: insert topic here
  id: 2017-ws
-
  semester: Wintersemester 2016
  topic: insert topic here
  id: 2016-ws
-
  semester: Sommersemester 2016
  topic: insert topic here
  id: 2016-ss
-
  semester: Wintersemester 2015
  topic: insert topic here
  id: 2015-ws-k
[…]

site/blueprints/pages/semesters.yml

title: semesters

options:
  delete: false
  status: false
  url: false

fields:
  semesters:
    label: Semesters
    type: structure
    sortable: false
    sortBy: id desc
    fields:
      semester:
        label: Semester
        type: text
        width: 1/4
        required: true
      topic:
        label: Topic
        type: text
        width: 2/4
        required: true
      id:
        label: Identifier
        type: text
        width: 1/4
        required: true

site/blueprints/pages/projects.yml

title: project

options:
  delete: false
  status: false
  url: false

columns:
  - width: 1/3
    sections:
      files:
        headline: Files
        type: files
        layout: list

  - width: 2/3
    fields:
      project:
        label: Title
        type: text
        required: true

      semester:
        label: Semester / Topic
        type: select
        options: query
          query:
            fetch: site.find("semesters").semesters.toStructure
            text: "{{ structureItem.semester }}: {{ structureItem.topic }}"
            value: "{{ structureItem.id }}"
        required: true

      text:
        label: Text
        type: textarea
        size: large
        buttons: false
        required: true

Still not sure where the issue is though. Gimme another couple of minutes

1 Like

Your indentation is not correct, at least not what you posted here. query should have the same indent as options

  semester:
        label: Semester / Topic
        type: select
        options: query
        query:
          fetch: site.find("semesters").semesters.toStructure
          text: "{{ structureItem.semester }}: {{ structureItem.topic }}"
          value: "{{ structureItem.id }}"
        required: true

That is actually why you see the literal value and no options at all.

1 Like

I was actually just now double checking the indentation of the blueprint.
Also, am I wrong or that is also the old syntax for the columns?

Talking about this part - width: 2/3

No, that is correct and the same as in the Starterkit.

Yeah … that fixed it. :smirk:

Thank you very much, @texnixe and @manuelmoreale

Ah, interesting. Good to know.

I thought this was the final syntax https://getkirby.com/docs/guide/blueprints/layout#defining-columns