Forum
Require alt text for optional images
What's the best way to make alt text required for optional images?
The following workarounds have come to my mind:
<perch:content type="image" id="img" label="Image" />
<perch:content type="text" id="imgAlt" required="true" label="Alt Text" help="If you don't have an image, fill in * "/>"
and then of course don't output the alt text if there's no image.
Or
<perch:repeater id="portrait" label="Portrait" max="1">
<perch:content type="image" id="img" required="true" label="Image" />
<perch:content type="text" id="imgAlt" required="true" />"
</perch:repeater>
which looked elegant in the first place, but it's not perfect, as the required fields are enforced at the second save only, and (please correct me if I'm mistaken) repeaters can't be used for previews in the admin list view.
From a developer's perspective, the ideal way would be like that:
<perch:content type="image" id="img" label="Image" />
<perch:content type="text" id="imgAlt" requiredif="img" label="Alt-Text"/>"
But that's made up.
What do you recommend?
We don't have field-dependency validation included at the current time.
I understand. Which workaround would you prefer if you had to pick one?
And is it correct that fields from repeaters can't be used as list columns? (Referring to this: https://grabaperch.com/blog/archive/customising-list-columns)
You should pick whichever you prefer for your circumstances.
That's correct, because they repeat by definition.