Skip to content

Commit

Permalink
Merge pull request #244 from nanddeepn/master
Browse files Browse the repository at this point in the history
Show only Time in PropertyFieldDateTimePicker
  • Loading branch information
AJIXuMuK authored May 15, 2020
2 parents e67ddab + b959b41 commit 59b4648
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Enum `DateConvention`
| ---- | ---- |
| DateTime | Shows the date and time picker |
| Date | Shows only the date picker |
| Time | Shows only the time picker |

Enum `TimeConvention`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export enum TimeConvention {
export enum DateConvention {

DateTime = 1,
Date
Date,
Time
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ export default class PropertyFieldDateTimePickerHost extends React.Component<IPr
* Save the new date
*/
private _saveDate(): void {
const { dateConvention } = this.props;

// If the DateConvention is Time, set the Date as today
if (dateConvention === DateConvention.Time) {
this._crntDate = new Date();
}

// Check if the current date object exists
if (this._crntDate === null) {
return;
Expand All @@ -206,11 +213,14 @@ export default class PropertyFieldDateTimePickerHost extends React.Component<IPr

if (finalDate !== null) {
let finalDateAsString: string = '';

if (this.props.formatDate) {
finalDateAsString = this.props.formatDate(finalDate);
} else {
finalDateAsString = finalDate.toString();
}
else {
finalDateAsString = dateConvention === DateConvention.Time ? finalDate.toTimeString() : finalDate.toString();
}

this.delayedValidate({
value: finalDate,
displayValue: finalDateAsString
Expand Down Expand Up @@ -297,7 +307,7 @@ export default class PropertyFieldDateTimePickerHost extends React.Component<IPr

// Check if the time element needs to be rendered
let timeElm: JSX.Element = <tr />;
if (dateConvention === DateConvention.DateTime) {
if (dateConvention === DateConvention.DateTime || dateConvention === DateConvention.Time) {
timeElm = (
<tr>
{showLabels && <td className={styles.labelCell}>
Expand Down Expand Up @@ -341,21 +351,23 @@ export default class PropertyFieldDateTimePickerHost extends React.Component<IPr
{label && <Label>{label}</Label>}
<table cellPadding='0' cellSpacing='0'>
<tbody>
<tr>
{showLabels && <td className={styles.labelCell}>
<Label className={styles.fieldLabel}>{strings.DateTimePickerDate}</Label>
</td>}
<td>
<DatePicker
disabled={disabled}
value={this.state.day}
strings={dateStrings}
isMonthPickerVisible={true}
onSelectDate={this._onSelectDate}
allowTextInput={false}
firstDayOfWeek={this.props.firstDayOfWeek} />
</td>
</tr>
{dateConvention !== DateConvention.Time &&
<tr>
{showLabels && <td className={styles.labelCell}>
<Label className={styles.fieldLabel}>{strings.DateTimePickerDate}</Label>
</td>}
<td>
<DatePicker
disabled={disabled}
value={this.state.day}
strings={dateStrings}
isMonthPickerVisible={true}
onSelectDate={this._onSelectDate}
allowTextInput={false}
firstDayOfWeek={this.props.firstDayOfWeek} />
</td>
</tr>
}
{!!timeElm &&
<tr>
<td className={styles.spacerRow} colSpan={showLabels ? 2 : 1}></td>
Expand All @@ -364,7 +376,6 @@ export default class PropertyFieldDateTimePickerHost extends React.Component<IPr
</tbody>
</table>


<FieldErrorMessage errorMessage={this.state.errorMessage} />
</div >
);
Expand Down

0 comments on commit 59b4648

Please sign in to comment.