Ok I am unsure how to better solve the following.
I have a structure field called “sizes”, which holds possible sizes for a product.
“Sizes” may be empty, but if it is NOT empty, then one “size” (and not more than one) must be marked as “default” somehow.
sizes:
label: Sizes
type: structure
fields:
size:
label: size
type: text
First I tried to add a “default” toggle to the size structureItem. But then the user may select more than one default, which is a little bit confusing:
sizes:
label: Sizes
type: structure
help: Only one size can be default
fields:
size:
label: size
type: text
default:
label: Default?
type: toggle
text:
- "no"
- "yes"
…as far as I know I can’t have a trans structure items radio button. As in a radio button on each structure item, that acts as a single radio group…
So my next attempt is a separate radio field that is populated via the contents of the structure field:
sizes:
label: Sizes
type: structure
fields:
size:
label: size
type: text
defaultsize:
label: Default size
type: radio
options: query
columns: 6
query:
fetch: page.sizes.toStructure
text: "{{ structureItem.size }}"
value: "{{ structureItem.size }}"
This has two downsides.
First, after adding structure items, the user has to reload in order to see them as selectable radio buttons.
Second, as far as I understand, I cannot “require” this radio field, because 1) user adds structure items 2) user tries to save 3) can’t save, “defaultsize” is required 4) can’t select anything in “defaultsize” because it is empty 5) panic
So… how would you suggest solving this?
Could I perhaps use when then condition, in a way that “defaultsize” is only required if not empty?
Although I would still have the problem of the user having to reload the page, after filling “sizes” in order to see “defaultsize” radio options
Thanks