Query another field in a select field

Hello,

I have created a structure field that holds multiple image galleries. Within each gallery I would like to be able to select on of the gallery images to be marked as active.

I am using the following code but don’t know what to query for or if this is possible at all.

galleries:
    label: Galleries
    type: structure
    fields:
        gallery:
            label: Gallery
            type: files
            query: page.images
        fetured:
            label: Featured
            type: select
            query:

I think your featured field should simply be a toggle field that is set to true for the selected image in the first field if the user wants to feature it.

galleries:
    label: Galleries
    type: structure
    fields:
        gallery:
            label: Gallery
            type: files
            max: 1
            query: page.images
        featured:
            label: Featured
            type: toggle
            text: Feature this image?

Per structure item you select one image and for that image, you set if this should be featured or not. Otherwise using a structure wouldn’t even make sense here.

The alternative would be to use a files section and store which image should be featured in the meta data.

1 Like

The user must be able to create separate galleries that have a max of 5 images. After he decided on which 5 images go to the specific gallery he then selects one of them to be featured.

So it should be:

gallery1

  • img1
  • img2
  • img3 ->featured
  • img4
  • img5

gallery2

  • img1
  • img2
  • img3
  • img4
  • img5->featured

Clients and their crazy requests, i know.

Oh, ok, but the problem is that you won’t be able to query the files from the blueprint. You would indeed need JavaScript to be able to query what has been selected in the first field in the second.

Instead of selecting the file, why not ask the user to put the featured image first (they can sort the images in the files field after all). Unless you need the order plus a featured image. If the featured image shouldn’t be the first image as well, then you will have to go down the JS route, I think.

Or use a nested structure field with the toggle field as explained above.

Because I need to apply separate styling to the featured image while retaining its order in the gallery. This is such a stupid request the more I think about it.

With such a structure it would work:

      galleries:
          label: Galleries
          type: structure
          fields:
              gallery:
                type: structure
                fields:
                  gallery_image:
                    type: files
                    max: 1
                    query: page.images
                  featured:
                    type: toggle
                    text: Feature this?

That means that for each gallery, the user has to select each image separately, and then for one of the items set the featured toggle to true. If the user happens to select more than one as featured, you have to get the first featured image.

1 Like