Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 40c7a8f

Browse files
Michael Chenjelbourn
authored andcommitted
feat(datepicker): Add invalid class for datepicker
Add a red border to the bottom of the datepicker input if the input string is not a valid and complete date.
1 parent 36d355a commit 40c7a8f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/components/datepicker/datePicker-theme.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ md-datepicker.md-THEME_NAME-theme {
88

99
.md-datepicker-input-container {
1010
border-bottom-color: '{{background-300}}';
11+
12+
&.md-datepicker-invalid {
13+
border-bottom-color: '{{warn-500}}';
14+
}
1115
}
1216

1317
.md-datepicker-calendar-pane {

src/components/datepicker/datePicker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// TODO(jelbourn): make sure this plays well with validation and ngMessages.
1010
// TODO(jelbourn): calendar pane doesn't open up outside of visible viewport.
1111
// TODO(jelbourn): forward more attributes to the internal input (required, autofocus, etc.)
12-
// TODO(jelbourn): error state
1312
// TODO(jelbourn): something better for mobile (calendar panel takes up entire screen?)
1413
// TODO(jelbourn): input behavior (masking? auto-complete?)
1514
// TODO(jelbourn): UTC mode
@@ -86,6 +85,9 @@
8685
/** Additional offset for the input's `size` attribute, which is updated based on its content. */
8786
var EXTRA_INPUT_SIZE = 3;
8887

88+
/** Class applied to the container if the date is invalid. */
89+
var INVALID_CLASS = 'md-datepicker-invalid';
90+
8991
/**
9092
* Controller for md-datepicker.
9193
*
@@ -214,7 +216,11 @@
214216

215217
if (self.dateUtil.isValidDate(parsedDate) && self.dateLocale.isDateComplete(inputString)) {
216218
self.ngModelCtrl.$setViewValue(parsedDate);
219+
self.inputContainer.classList.remove(INVALID_CLASS);
217220
self.$scope.$apply();
221+
} else {
222+
// If there's an input string, it's an invalid date.
223+
self.inputContainer.classList.toggle(INVALID_CLASS, inputString);
218224
}
219225
});
220226
};

0 commit comments

Comments
 (0)