Fetch options for blueprint select field from tags field within same structure field


#1

I’m trying to use the structure field for a quiz backend where each question is an entry in a structure field. The structure field contains question, answer-options (tags field) and a select field for choosing which of these options that is the correct answer.

Can’t figure out how to query the answeroptions - if possible:

  quizentry:
    label: Quiz entry
    type: structure
    fields:
      question:
        label: Question
        type: text
      answeroptions:
        label: Answer options
        type: tags
      correctanswer:
        label: Correct answer
        type: select
        options: query
        query:
          fetch: page.quizentry.toStructure.??? (can I dig into the structure here?)
          text: "{{??structureItem.options???}}"

Looked into this related question, but split doesn’t seem to help when it’s within the same structure field: Fetch tags as options from another tags field inside a blueprintPreformatted text


#2

I don’t think this is possible. First, you want to select something that hasn’t even been stored yet, secondly, the structureItem selects a single field from all items in the structure, so selecting a field that itself contains an array wouldn’t be possible unless you use the API option for this. Then again, only once the content has been saved.

For this to work you would need a custom field plugin that uses JavaScript to read the tags from the answeroptions field and inject them on the fly into the correctanswer options.


#3

Ah, ok - I misunderstood the page.field query, thought it was querying the DOM, so you could get values from the same page without saving.

When I have saved I do get something that seems to be in the right direction, though

But thanks for the tip, I’ll look into the field plugin.


#4

Yes, but your result is not really what you need. While it should be possible to get the right values either through the API option or through a custom method, it wouldn’t make sense from a workflow perspective to first have to save and then revisit the field to select the correct answer.