Background: Generally, Slate stores date values in custom fields as text. When using forms to input dates, the Calendar element (jQuery's datepicker) stores dates like yyyy-MM-dd. However, the Date form element (a group of three select elements) stores values like yyyyMMdd.
This whole topic is a sore spot and causes some strange issue when storing and retrieving data via forms and widget tables. Queries generally use try_cast() and function fine. We can work around the form issues with a few tricks.
Use a Default Value Formula:
Set the Format Type to Date and the Format Mask to:
yyyyMMdd
As above, use a Default Value Formula, but this time, set the Format Mask to:
yyyy-MM-dd
You may also be able to leave the Format Mask blank, as it should default to the above format, which matches the SQL Server default date format.
Sometimes the above doens't work, such as in Reader-scoped forms. In that case, we have to get our hands dirty with a bit of JavaScript.
Create Merge Field exports that our JavaScript can use. Split month and year into two separate fields:
Place a script like the following in an Instruction block on the form:
<script> // Wait for the page to finish loading $(function () { $("[data-export='sys:school:conferred'] select[aria-label='Month']").val('{{school_conferred_date_m}}'); $("[data-export='sys:school:conferred'] select[aria-label='Year']").val('{{school_conferred_date_y}}'); $("[data-export='sys:school:from'] select[aria-label='Month']").val('{{school_from_date_m}}'); $("[data-export='sys:school:from'] select[aria-label='Year']").val('{{school_from_date_y}}'); $("[data-export='sys:school:to'] select[aria-label='Month']").val('{{school_to_date_m}}'); $("[data-export='sys:school:to'] select[aria-label='Year']").val('{{school_to_date_y}}'); }); </script>