Browse Source

Allow more date formats (#47)

* Update moment version.

* Add more allowable date formats.

* Field should not be required.
feature/travis-only-master
Drew Larson 8 years ago
committed by GitHub
parent
commit
32416d6b8f
  1. 8
      bikeshop_project/registration/forms.py
  2. 5
      bikeshop_project/registration/templates/edit_member_form.html
  3. 5
      bikeshop_project/registration/templates/member_form.html

8
bikeshop_project/registration/forms.py

@ -1,11 +1,16 @@
from django.forms import ModelForm, EmailInput, TextInput, DateInput, CheckboxInput, BooleanField, Textarea
from django.forms import ModelForm, EmailInput, TextInput, DateInput, CheckboxInput, BooleanField, Textarea, DateField
from django.utils import timezone
from registration.models import Member
class MemberForm(ModelForm):
input_formats = ['%Y-%m-%d', '%y-%m-%d', '%d-%m-%y', '%d-%m-%Y',
'%Y/%m/%d', '%y/%m/%d', '%d/%m/%y', '%d/%m/%Y']
waiver_substitute = BooleanField(required=False, label='I have read and agree to the above terms & conditions.',
widget=CheckboxInput(attrs={'class': 'mdl-checkbox__input'}))
date_of_birth = DateField(required=False, input_formats=input_formats,
widget=DateInput(attrs={'class': 'mdl-textfield__input'}))
class Meta:
model = Member
@ -20,7 +25,6 @@ class MemberForm(ModelForm):
'first_name': TextInput(attrs={'class': 'mdl-textfield__input'}),
'last_name': TextInput(attrs={'class': 'mdl-textfield__input'}),
'preferred_name': TextInput(attrs={'class': 'mdl-textfield__input'}),
'date_of_birth': DateInput(attrs={'class': 'mdl-textfield__input'}),
'guardian_name': DateInput(attrs={'class': 'mdl-textfield__input', 'disabled': 'disabled'}),
'phone': TextInput(attrs={'class': 'mdl-textfield__input', 'pattern': '[0-9]*'}),
'street': TextInput(attrs={'class': 'mdl-textfield__input'}),

5
bikeshop_project/registration/templates/edit_member_form.html

@ -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;

5
bikeshop_project/registration/templates/member_form.html

@ -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;

Loading…
Cancel
Save