# Populating select field via query of structure field not working

**URL:** <https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908>\
**Category:** Questions\
**Tags:** v3\
**Created:** [October 10, 2019, 5:07am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908 "2019-10-10T05:07:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 10, 2019, 5:07am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/1 "2019-10-10T05:07:06Z")

</div>

I have a structure field on a page like this:

```yaml
form_fields:
  type: structure
  label: Form Fields
  fields:
    form_field_name:
      type: text
      label: Field Name
    form_field_class:
      type: text
      label: Field Class
    form_field_structure:
      type: toggle
      label: Field Structure
      default: false
      text:
        - plain element
        - enclose in &lt;div&gt;

```

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:

```yaml
form_key_field:
  type: select
  label: Key Field
  options: query
  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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 10, 2019, 6:34am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/2 "2019-10-10T06:34:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 10, 2019, 6:37am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/3 "2019-10-10T06:37:29Z")

</div>

It’s the latest, @texnixe - 3.2.5.

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 10, 2019, 6:43am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/4 "2019-10-10T06:43:57Z")

</div>

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

 ![14](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/3/3c74b3f8789613df73627de5030170fb6213c575.png)

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

---

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 10, 2019, 6:46am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/5 "2019-10-10T06:46:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 10, 2019, 6:47am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/6 "2019-10-10T06:47:29Z")

</div>

Do you have another field with the same name somewhere?

---

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 10, 2019, 6:48am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/7 "2019-10-10T06:48:58Z")

</div>

No - literally _just_ checked that! 🙂

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

---

<div class="post-metadata">

**Author:** ![luxlogica](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/luxlogica/32/437_2.png) [@luxlogica](https://forum.getkirby.com/u/luxlogica)\
**Post date:** [October 10, 2019, 6:56am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/8 "2019-10-10T06:56:26Z")

</div>

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! 🙄

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 10, 2019, 6:58am UTC](https://forum.getkirby.com/t/populating-select-field-via-query-of-structure-field-not-working/15908/9 "2019-10-10T06:58:57Z")

</div>

> [@luxlogica](#):
>
> do you have any suggestions for a solution that wouldn’t involve save+reloading the page?.

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