First Query Result as default in Multiselect

Hi,

I’m trying to get the first page of a query as a default value for a multiselect-field.
Is this possible somehow?

album:
  label: Album
  type: multiselect
  options: query
  query:
    fetch: page.childrenAndDrafts.template("album")
    text: "{{ page.title }}"
    value: "{{ page.slug }}"
  default: page.childrenAndDrafts.template("album").first

Hi Cris,

You can create a model for the page you’re querying, and do whatever you like in that model (fetching and sorting things). Then you can use that in the querylanguage in the blueprint.

E.g.: model with e.g. myAlbums and myFirstAlbum method -> page.myFirstAlbum.

More info:

1 Like

Thanks a lot! I’ll give it a try! :slight_smile:

Wait, have you already tried page.childrenAndDrafts.template("album").first.slug?

Yes, unfortunately it doesn’t work.
But I’m also using it as a field in a builder plugin, maybe this could be a problem too, as the docs say this:

Default value for the field, which will be used when a page/file/user is created

I don’t think this is possible, only a few fields actually support query language for the default option, it seems. It works for the textarea field, for example.

@bvdputte Have you used this successfully somewhere?

@Cris Default only works at page creation, that’s right.

1 Like

@texnixe, not really. I’m using my “Kirby experience points” here :slight_smile:

I’m surprised that it doesn’t tbh🤔. It feels not very kirby-like to only have it working in certain fields.

Ok, it’s not a big deal,… would just have been a nice to have =)
Thanks anyway!

If the field is required, you could probably use the API query option to force the first child to the beginning. It would then be auto-selected, I think. (not tested)

On a side note: Interestingly, providing a default for a textarea field inside a structure works:

    fields:
      album:
        label: Album
        type: structure
        fields:
          text:
            type: textarea
            default: "{{ site.globaltext }}"
1 Like

Could be an option! I’ll play around with that as soon as I find some time. :slight_smile: