Allow more date formats (#47)

* Update moment version.

* Add more allowable date formats.

* Field should not be required.
This commit is contained in:
Drew Larson
2017-05-17 21:29:46 -06:00
committed by GitHub
parent 6764c289ff
commit 32416d6b8f
3 changed files with 12 additions and 6 deletions
@@ -2,7 +2,7 @@
{% load staticfiles %}
{% block scripts %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script>
var dateOfBirthInput = document.getElementById('{{ form.date_of_birth.id_for_label }}');
var submitButton = document.getElementById('submit');
@@ -12,7 +12,8 @@
input.parentNode.classList.add('is-dirty');
var threshold = moment.duration(18, 'years');
var dob = moment(input.value, 'YYYY-MM-DD');
var dob = moment(input.value, ['YYYY-MM-DD', 'YY-MM-DD', 'DD-MM-YY', 'DD-MM-YYYY',
'YYYY/MM/DD', 'YY/MM/DD', 'DD/MM/YY', 'DD/MM/YYYY']);
if (dob.add(threshold).isAfter(moment())) {
document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false;
@@ -2,7 +2,7 @@
{% load staticfiles %}
{% block scripts %}
<script src="{% static 'vendor/moment/min/moment.min.js' %}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script>
dateOfBirthInput = document.getElementById('{{ form.date_of_birth.id_for_label }}');
@@ -11,7 +11,8 @@
input.parentNode.classList.add('is-dirty');
var threshold = moment.duration(18, 'years');
var dob = moment(input.value, 'YYYY-MM-DD');
var dob = moment(input.value, ['YYYY-MM-DD', 'YY-MM-DD', 'DD-MM-YY', 'DD-MM-YYYY',
'YYYY/MM/DD', 'YY/MM/DD', 'DD/MM/YY', 'DD/MM/YYYY']);
if (dob.add(threshold).isAfter(moment())) {
document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false;