mirror of
https://github.com/fspc/workstand.git
synced 2025-02-23 09:13:23 -05:00
Allow more date formats (#47)
* Update moment version. * Add more allowable date formats. * Field should not be required.
This commit is contained in:
parent
6764c289ff
commit
32416d6b8f
@ -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 django.utils import timezone
|
||||||
from registration.models import Member
|
from registration.models import Member
|
||||||
|
|
||||||
|
|
||||||
class MemberForm(ModelForm):
|
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.',
|
waiver_substitute = BooleanField(required=False, label='I have read and agree to the above terms & conditions.',
|
||||||
widget=CheckboxInput(attrs={'class': 'mdl-checkbox__input'}))
|
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:
|
class Meta:
|
||||||
model = Member
|
model = Member
|
||||||
@ -20,7 +25,6 @@ class MemberForm(ModelForm):
|
|||||||
'first_name': TextInput(attrs={'class': 'mdl-textfield__input'}),
|
'first_name': TextInput(attrs={'class': 'mdl-textfield__input'}),
|
||||||
'last_name': TextInput(attrs={'class': 'mdl-textfield__input'}),
|
'last_name': TextInput(attrs={'class': 'mdl-textfield__input'}),
|
||||||
'preferred_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'}),
|
'guardian_name': DateInput(attrs={'class': 'mdl-textfield__input', 'disabled': 'disabled'}),
|
||||||
'phone': TextInput(attrs={'class': 'mdl-textfield__input', 'pattern': '[0-9]*'}),
|
'phone': TextInput(attrs={'class': 'mdl-textfield__input', 'pattern': '[0-9]*'}),
|
||||||
'street': TextInput(attrs={'class': 'mdl-textfield__input'}),
|
'street': TextInput(attrs={'class': 'mdl-textfield__input'}),
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% 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>
|
<script>
|
||||||
var dateOfBirthInput = document.getElementById('{{ form.date_of_birth.id_for_label }}');
|
var dateOfBirthInput = document.getElementById('{{ form.date_of_birth.id_for_label }}');
|
||||||
var submitButton = document.getElementById('submit');
|
var submitButton = document.getElementById('submit');
|
||||||
@ -12,7 +12,8 @@
|
|||||||
input.parentNode.classList.add('is-dirty');
|
input.parentNode.classList.add('is-dirty');
|
||||||
|
|
||||||
var threshold = moment.duration(18, 'years');
|
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())) {
|
if (dob.add(threshold).isAfter(moment())) {
|
||||||
document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false;
|
document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% 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>
|
<script>
|
||||||
dateOfBirthInput = document.getElementById('{{ form.date_of_birth.id_for_label }}');
|
dateOfBirthInput = document.getElementById('{{ form.date_of_birth.id_for_label }}');
|
||||||
|
|
||||||
@ -11,7 +11,8 @@
|
|||||||
input.parentNode.classList.add('is-dirty');
|
input.parentNode.classList.add('is-dirty');
|
||||||
|
|
||||||
var threshold = moment.duration(18, 'years');
|
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())) {
|
if (dob.add(threshold).isAfter(moment())) {
|
||||||
document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false;
|
document.getElementById('{{ form.guardian_name.id_for_label }}').disabled = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user