How to bypass required theme.ini element date field?

Hi there,
I want to include an OPTIONAL date field in my theme.ini file, but it’s requiring that it is filled before saving. Does anyone know of a way to bypass this requirement? The date is only needed if the first question is yes, that the site is sunsetted. Here is what I have in my theme.ini file for this segment:

elements.sunsetsite.type = “select”
elements.sunsetsite.name = “sunsetsite”
elements.sunsetsite.options.label = “Is this site sunsetted?”
elements.sunsetsite.options.info = “Is this site no longer accepting updates and should remain limited?”
elements.sunsetsite.options.options.no = “no”
elements.sunsetsite.options.options.yes = “yes”

elements.sunsetdate.type = “date”
elements.sunsetdate.name = “sunsetdate”
elements.sunsetdate.options.label = “When was this sunsetted?”
elements.sunsetdate.options.info = “Please select the date in which this site is no longer supported”

Thanks!

I think the issue is that a date input is “required” by default, and we don’t provide a way for themes to set that required flag. Some form elements provided by Laminas are like this, and start out as “required” while most don’t.

So, the answer is basically that you can’t use a Date input for a theme config setting right now. You could use a workaround instead, a simple text field, or possibly using the “pattern” attribute if you want to force input in a particular date format (but you won’t get the calendar-picker interface).

Ahh ok, thank you so much for pointing this out and saving me more headaches trying to research a solution that doesn’t exist! I do like your workaround idea though, of just using a simple text field and perhaps using the pattern attribute. I haven’t used that before but I will look into it. Thanks!

We’re looking into changes we can make on our end to allow more elements like this in the future, as well.

1 Like

For this point, it’s possible to create optional elements, as I do in some modules: src/Form/Element · master · Daniel-KM / Omeka S Module Advanced Search · GitLab I can push them to omeka core if you want.

Hi, thank you for pointing out this possibility! As of right now I would say our need for it doesn’t warrant the trouble. I appreciate it though!

What we’re looking at to add is hooking things up to 1) set everything to non-required by default in these theme forms, including elements like “date” and 2) let theme writers opt in to things being actually required, by using elements.an_element.attributes.required = true.

Right now that doesn’t quite work for these “default required” elements so the change to allow this would be in a future core update.

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.