Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Fix DatePicker + DateTimeField to return null and set value to empty …
Browse files Browse the repository at this point in the history
…when the value is removed (#86)

When we remove the value entirely from the date field, the value being returned in 'invalid' which in a sense breaks the validation as it is not a date expected. Adding a fix to return the value as null in order to let validation succeed as a empty string in the date field is essentially right.
  • Loading branch information
chsomani authored Aug 5, 2019
1 parent 204fea4 commit 1942eb1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v6.3.4
### Fixed
- Fix DatePicker + DateTimeField to return empty string and set value to empty when the value is removed

## v6.3.3
### Fixed
- Fix alignment of items inside action trigger button and buttons.
Expand Down
2 changes: 1 addition & 1 deletion lib/components/DateTime/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class DatePicker extends React.Component<DatePickerProps, Partial<DatePic

this.props.onChange(dateValue.dateObject.toJSON());
} else {
this.props.onChange('invalid');
this.props.onChange(newValue === '' ? newValue : 'invalid');
this.setState({value: newValue});
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/components/DateTime/DateTimeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ export class DateTimeField extends React.Component<DateTimeFieldProps, Partial<D
}

onChange = (newDate: string | Date, newTime: string | Date): Date => {
if (newDate === '') {
this.props.onChange(newDate);
return null;
}
if (newDate === 'invalid' || newTime === 'invalid' || !newDate || !newTime) {
this.props.onChange('invalid');
return null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/azure-iot-ux-fluent-controls",
"version": "6.3.3",
"version": "6.3.4",
"description": "Azure IoT UX Fluent Controls",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down

0 comments on commit 1942eb1

Please sign in to comment.