Skip to content

Commit

Permalink
addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Jan 11, 2017
1 parent 03d694a commit 1efd8f9
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/lib/input/input-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,11 @@ export class MdInputDirective {
@Output() _placeholderChange = new EventEmitter<string>();

get empty() {
if (this._isNeverEmpty()) {
return false;
}
if (this.value == null || this.value === '') {
// Check if this is an <input> element that contains bad input.
// If so, we know that it only appears empty because the value failed to parse.
if (this._elementRef.nativeElement instanceof HTMLInputElement &&
this._elementRef.nativeElement.validity.badInput) {
return false;
}
return true;
}
return false;
return !this._isNeverEmpty() &&
(this.value == null || this.value === '') &&
// Check if the input contains bad input. If so, we know that it only appears empty because
// the value failed to parse. From the user's perspective it is not empty.
!this._isBadInput();
}

private get _uid() { return this._cachedUid = this._cachedUid || `md-input-${nextUniqueId++}`; }
Expand Down Expand Up @@ -213,6 +205,10 @@ export class MdInputDirective {

private _isNeverEmpty() { return this._neverEmptyInputTypes.indexOf(this._type) !== -1; }

private _isBadInput() {
return (this._elementRef.nativeElement as HTMLInputElement).validity.badInput;
}

/** Determines if the component host is a textarea. If not recognizable it returns false. */
private _isTextarea() {
let nativeElement = this._elementRef.nativeElement;
Expand Down

0 comments on commit 1efd8f9

Please sign in to comment.