This is useful for forms that ask the user to enter today’s date. If the date is automatically entered, it saves time (and prevents them from back/forward-dating it.)
How To
Place this script below the scripts.mustache call within the mustache file for your form. It’s not placed within any of the actual script files so that we can guarantee it happens at the right time.
Note that if you have multiple date fields, you’ll need to copy and paste what’s inside the script tags and use it twice. Make sure to update the IDs to be calling the correct field(s) for your form.
<script type="text/javascript">
Date.prototype.toDateInputValue = (function() {
var local = new Date(this);
local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
return local.toJSON().slice(0,10);
});
document.getElementById('voluntaryDisclosureTodaysDate').value = new Date().toDateInputValue();
document.getElementById('veteranTodaysDate').value = new Date().toDateInputValue();
document.getElementById('disabilityTodaysDate').value = new Date().toDateInputValue();
</script>
Tags: bs2, bs3, bs4, form, script, js, javascript, html