Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show only Time in PropertyFieldDateTimePicker #244

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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