Skip to content

Commit

Permalink
fix(datetime): clear out existing datetime data
Browse files Browse the repository at this point in the history
Closes #6614
  • Loading branch information
adamdbradley committed Jun 1, 2016
1 parent f7b1f37 commit c1ad804
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/datetime/test/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ class E2EPage {
'l\u00f8r'
];

onChange(ev) {
onChange(ev: any) {
console.log("Changed", ev);
}

onCancel(ev) {
onCancel(ev: any) {
console.log("Canceled", ev);
}

clearLeapYear() {
this.leapYearsSummerMonths = null;
}

}


Expand Down
2 changes: 2 additions & 0 deletions src/components/datetime/test/basic/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@
<code>Leap year, summer months: {{leapYearsSummerMonths}}</code><br>
</p>

<button (click)="clearLeapYear()">Clear Leap Years</button>

</ion-content>
14 changes: 14 additions & 0 deletions src/components/datetime/test/datetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,20 @@ describe('DateTime', () => {
expect(datetime.getValue()).toEqual({});
});

it('should clear out existing value with blank value', () => {
datetime.setValue('1994-12-15T13:47:20.789Z');
datetime.setValue(null);
expect(datetime.getValue()).toEqual({});

datetime.setValue('1994-12-15T13:47:20.789Z');
datetime.setValue(undefined);
expect(datetime.getValue()).toEqual({});

datetime.setValue('1994-12-15T13:47:20.789Z');
datetime.setValue('');
expect(datetime.getValue()).toEqual({});
});

it('should not parse a value with blank value', () => {
datetime.setValue(null);
expect(datetime.getValue()).toEqual({});
Expand Down
6 changes: 6 additions & 0 deletions src/util/datetime-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ export function updateDate(existingData: DateTimeData, newData: any) {

// eww, invalid data
console.warn(`Error parsing date: "${newData}". Please provide a valid ISO 8601 datetime format: https://www.w3.org/TR/NOTE-datetime`);

} else {
// blank data, clear everything out
for (var k in existingData) {
delete existingData[k];
}
}
}

Expand Down

0 comments on commit c1ad804

Please sign in to comment.