Populating select field via query of structure field not working

I have a structure field on a page like this:

  type: structure
  label: Form Fields
      type: text
      label: Field Name
      type: text
      label: Field Class
      type: toggle
      label: Field Structure
      default: false
        - plain element
        - enclose in <div>

I’d like to create a SELECT field now, on the same page, which should have selections based on the entries in that field. I’m trying this:

  type: select
  label: Key Field
  options: query
    fetch: page.form_fields.toStructure
    text: "#{{ structureItem.form_field_name }}"
    value: "{{ structureItem.form_field_name }}"

But all I get is an error message where the select field should be, which says:

Error in "form_key_field" field: 
Invalid query result data

I’ve also tried using yaml + arrayItem in the query, instead of toStructure and structureItem, but got same result.

Any suggestions would be greatly appreciated.

Hm, I can’t reproduce the error with your above code. What is your Kirby version?

It’s the latest, @texnixe - 3.2.5.

This blueprint code is actually part of a PLUGIN. Could that be the problem?..

I moved it into a plugin, which also works. How do you register the file?

Downside with this approach is that you have to first save the page then reload…

Yes, I moved the code out of the plugin and pasted it directly into the page’s blueprint, and am still getting the error - so that’s not it. Damn it.

If you’re not getting any issues, then it must be something else on the blueprint that is causing the problem. Let me do some logical troubleshooting to see if I can pinpoint it.

Do you have another field with the same name somewhere?

No - literally just checked that! :slight_smile:

BTW: do you have any suggestions for a solution that wouldn’t involve save+reloading the page?.. All ideas are welcome!

Ok, found the problem.

I was doing my testing directly in site.yml, so instead of page.form_fields.toStructure I should have done site.form_fields.toStructure - doh! :roll_eyes:

You would need a select field that listens to changes in the structure field and injects/updates the options.