Select field query default value

Hi there,

I have a select field in my blueprint, where I retrieve the available options by the query field:

signature:
  type: select
  label: Signature
  empty: false
  required: true
  options: query
  query: "site.find('signatures').children().sortBy('title', 'desc')"

The objective is to select a page, which contains the signature. By default the newest one should be selected, when creating new pages.

So I want to have the first field in the queried collection to be the default value for this field and tried various approaches:

default: "{{ site.find('signatures').children().sortBy('title', 'desc').first }}"

default: "{{ site.find('signatures').children().sortBy('title', 'desc').first.id }}"

default: "{{ site.find('signatures').children().sortBy('title', 'desc').first.uri }}"

default: "signatures/{{ site.find('signatures').children().sortBy('title', 'desc').uid }}"

But non of them worked as expected and I cannot really find an example or possible solutions in the docs. I hope somebody can help me. I’ve put these codes in the help field to see the output, where it gave me the correct value. I do not know, if I am doing something wrong or this is simply not intended to work as I thought.

I am using Kirby v3.
Just let me know, if you need any further information.

Best wishes,
Chris

I’m never really sure where queries for default (or other properties) work or not.

In any case, this doesn’t seem to work. As a workaround, you could use a page model that stores the desired value at page creation.

Is it really necessary that the value is stored at page creation? Because when the field is required, the first option will be preselected anyway and will be stored as soon as the page is updated.

On a side note, the pages field might be a better option for selecting pages?

Thank you for your quick answer.

I’m never really sure where queries for default (or other properties) work or not.

That’s my problem.

Because when the field is required, the first option will be preselected anyway and will be stored as soon as the page is updated.

I tried this, but when I create a new page, the first value is not displayed as selected. Does it change, when I save the page?

Hm, you are right, somehow it doesn’t work as expected.

I’d go for a page model then.