diff --git a/atst/routes/users.py b/atst/routes/users.py index 30564196..b9325f93 100644 --- a/atst/routes/users.py +++ b/atst/routes/users.py @@ -38,4 +38,11 @@ def update_user(): if next_url: return redirect(next_url) - return render_template("user/edit.html", form=form, user=user, next=next_url) + return render_template( + "user/edit.html", + form=form, + user=user, + next=next_url, + mindate=(dt.datetime.now() - dt.timedelta(days=365)), + maxdate=dt.datetime.now(), + ) diff --git a/js/components/date_selector.js b/js/components/date_selector.js index 8103ad23..1d7f49dd 100644 --- a/js/components/date_selector.js +++ b/js/components/date_selector.js @@ -12,7 +12,7 @@ var paddedNumber = function(number) { export default Vue.component('date-selector', { props: ['initialday', 'initialmonth', 'initialyear', 'mindate', 'maxdate'], - data: function() { + data() { return { day: this.initialday, month: this.initialmonth, @@ -20,35 +20,55 @@ export default Vue.component('date-selector', { } }, - computed: { - formattedDate: function() { - if (!this.isDateValid) { - return null + watch: { + month(newMonth, oldMonth) { + if (!!newMonth && newMonth.length > 2) { + this.month = oldMonth } + }, + day(newDay, oldDay) { + if (!!newDay && newDay.length > 2) { + this.day = oldDay + } + }, + + year(newYear, oldYear) { + if (!!newYear && newYear.length > 4) { + this.year = oldYear + } + }, + }, + + computed: { + formattedDate() { let day = paddedNumber(this.day) let month = paddedNumber(this.month) + if (!day || !month || !this.year) { + return null + } + return `${month}/${day}/${this.year}` }, - isMonthValid: function() { + isMonthValid() { var _month = parseInt(this.month) return _month >= 0 && _month <= 12 }, - isDayValid: function() { + isDayValid() { var _day = parseInt(this.day) return _day >= 0 && _day <= this.daysMaxCalculation }, - isYearValid: function() { + isYearValid() { return parseInt(this.year) >= 1 }, - isWithinDateRange: function() { + isWithinDateRange() { let _mindate = this.mindate ? Date.parse(this.mindate) : null let _maxdate = this.maxdate ? Date.parse(this.maxdate) : null let _dateTimestamp = Date.UTC(this.year, this.month - 1, this.day) @@ -64,7 +84,7 @@ export default Vue.component('date-selector', { return true }, - isDateValid: function() { + isDateValid() { return ( this.day && this.month && @@ -76,7 +96,7 @@ export default Vue.component('date-selector', { ) }, - daysMaxCalculation: function() { + daysMaxCalculation() { switch (parseInt(this.month)) { case 2: // February if (this.year) { @@ -100,7 +120,7 @@ export default Vue.component('date-selector', { }, }, - render: function(createElement) { + render(createElement) { return createElement('p', 'Please implement inline-template') }, }) diff --git a/styles/components/_forms.scss b/styles/components/_forms.scss index 7c549f01..598b2dae 100644 --- a/styles/components/_forms.scss +++ b/styles/components/_forms.scss @@ -116,7 +116,7 @@ } } -.date-picker { +.usa-input.date-picker { display: inline-block; margin-top: 10px; width: 100%; @@ -138,7 +138,13 @@ } } + input.usa-input-error:focus { + border-color: $color-red !important; + box-shadow: none; + } + input.usa-input-error { + padding-left: 11px; right: 0; } @@ -147,8 +153,16 @@ } p.usa-input-error-message { - padding-top: 20px; display: inline-block; + line-height: 26px; + margin-bottom: 0; + padding-top: 10px; + visibility: hidden; + width: 100%; + + &.form-has-errors { + visibility: inherit; + } } } diff --git a/templates/components/date_picker.html b/templates/components/date_picker.html index b66f7ec0..f229b735 100644 --- a/templates/components/date_picker.html +++ b/templates/components/date_picker.html @@ -13,7 +13,7 @@
- +
@@ -58,10 +58,10 @@
-

- {% if maxdate and mindate %}Date must be between {{maxdate.strftime("%Y-%m-%d")}} and {{mindate.strftime("%Y-%m-%d")}}{% endif %} - {% if maxdate and not mindate %}Date must be before or on {{maxdate.strftime("%Y-%m-%d")}}{% endif %} - {% if mindate and not maxdate %}Date must be after or on {{mindate.strftime("%Y-%m-%d")}}{% endif %} +

+ {% if maxdate and mindate %}Date must be between {{maxdate.strftime("%m/%d/%Y")}} and {{mindate.strftime("%m/%d/%Y")}}{% endif %} + {% if maxdate and not mindate %}Date must be before or on {{maxdate.strftime("%m/%d/%Y")}}{% endif %} + {% if mindate and not maxdate %}Date must be after or on {{mindate.strftime("%m/%d/%Y")}}{% endif %}