Skip to content

Commit fe14f04

Browse files
committed
Bug fix and enhancement
Fix : #13 Enhancement : #10
1 parent 647e4bc commit fe14f04

7 files changed

Lines changed: 1450 additions & 1142 deletions

File tree

Solution/Other/Solution.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<LocalizedName description="TimePicker PCF" languagecode="1033" />
99
</LocalizedNames>
1010
<Descriptions />
11-
<Version>1.0</Version>
11+
<Version>1.0.0.7</Version>
1212
<!-- Solution Package Type: Unmanaged(0)/Managed(1)/Both(2)-->
1313
<Managed>2</Managed>
1414
<Publisher>

TimePicker/ControlManifest.Input.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<manifest>
3-
<control namespace="DR" constructor="TimePicker" version="1.0.9" display-name-key="TimePicker" description-key="TimePicker control based on React time Picker (rc-time-picker)" control-type="standard" preview-image="img/timepicker-preview.png">
3+
<control namespace="DR" constructor="TimePicker" version="1.0.10" display-name-key="TimePicker" description-key="TimePicker control based on React time Picker (rc-time-picker)" control-type="standard" preview-image="img/timepicker-preview.png">
44
<!-- property node identifies a specific, configurable piece of data that the control expects from CDS -->
55
<property name="hourvalue" display-name-key="Hour Value Field" description-key="Bind this property to the field where you want to store the hour value" of-type="Whole.None" usage="bound" required="true" />
66
<property name="minutevalue" display-name-key="Minute Value Field" description-key="Bind this property to the field where you want to store the minute value" of-type="Whole.None" usage="bound" required="true" />
77

8-
8+
<property name="displaytype" display-name-key="Display Type" description-key="Display Type" of-type="Enum" usage="input" required="true">
9+
<value name="12hrs" display-name-key="12hrs" description-key="12hrs">12 hrs</value>
10+
<value name="24hrs" display-name-key="24hrs" description-key="24hrs">24 hrs</value>
11+
</property>
912

1013
<resources>
1114
<code path="index.ts" order="1"/>

TimePicker/TimePickerTextBox.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { FontIcon,Stack,TextField,mergeStyles} from "@fluentui/react";
66

77

88

9-
//todo : parametrize this
10-
const format = 'h:mm a';
9+
1110

1211
export interface IProps {
1312
hourvalue: number|undefined;
1413
minutevalue: number|undefined;
1514
readonly:boolean;
1615
masked:boolean;
16+
format:"h:mm a"|"k:mm";
17+
use12Hours:boolean;
18+
1719

1820
onChange: (hourvalue:number|undefined,minutevalue:number|undefined) => void;
1921
}
@@ -97,8 +99,8 @@ const TimePickerTextBox = (props : IProps): JSX.Element => {
9799
value={timevalue}
98100
className="time"
99101
onChange={handleChange}
100-
format={format}
101-
use12Hours
102+
format={props.format}
103+
use12Hours={props.use12Hours}
102104
inputReadOnly
103105
disabled={props.readonly}
104106
/>

TimePicker/css/TimePicker.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
width: 100%;
4343
position: relative;
4444
display: inline-block;
45-
padding: 4px 7px;
45+
padding: 4px 0px;
4646
height: 35px;
4747
cursor: text;
4848
font-size: 14px;

TimePicker/index.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TimePickerTextBox , {IProps} from "./TimePickerTextBox";
55

66
export class TimePicker implements ComponentFramework.StandardControl<IInputs, IOutputs> {
77

8-
private _firstrender:boolean = true; //will be put to false after first render
8+
99
private _hourvalue:number|undefined;
1010
private _minutevalue:number|undefined;
1111
private _notifyOutputChanged:() => void;
@@ -14,6 +14,8 @@ export class TimePicker implements ComponentFramework.StandardControl<IInputs, I
1414
minutevalue : undefined,
1515
readonly:false,
1616
masked:false,
17+
format:"h:mm a",
18+
use12Hours:true,
1719
onChange : this.notifyChange.bind(this) };
1820

1921
/**
@@ -64,24 +66,23 @@ export class TimePicker implements ComponentFramework.StandardControl<IInputs, I
6466
//Prepare props for component rendering
6567
this._hourvalue = context.parameters.hourvalue.raw !== null ? context.parameters.hourvalue.raw : undefined;
6668
this._minutevalue = context.parameters.minutevalue.raw !== null ? context.parameters.minutevalue.raw : undefined;
69+
let display = context.parameters.displaytype.raw;
70+
6771

68-
//RENDER ONLY IF DIFFERENT
69-
if(this.shouldRender())
70-
{
7172
//update the props
7273
this._props.hourvalue = this._hourvalue;
7374
this._props.minutevalue = this._minutevalue;
7475
this._props.readonly = isReadOnly;
7576
this._props.masked = isMasked;
77+
this._props.use12Hours = display === "12 hrs";
78+
this._props.format = display === "12 hrs" ? "h:mm a" : "k:mm";
7679

7780
ReactDOM.render(
7881
React.createElement(TimePickerTextBox, this._props)
7982
, this._container
8083
);
81-
if(this._firstrender){
82-
this._firstrender = false;
83-
}
84-
}
84+
85+
8586

8687
}
8788

@@ -116,14 +117,5 @@ export class TimePicker implements ComponentFramework.StandardControl<IInputs, I
116117
this._notifyOutputChanged(); //=> will trigger getOutputs
117118
}
118119

119-
private shouldRender = ():boolean =>
120-
{
121-
return this._firstrender || //Always render on first pass
122-
((this._props.hourvalue !== this._hourvalue //Values received must have changed
123-
||
124-
this._props.minutevalue !== this._minutevalue) &&
125-
(this._hourvalue === undefined && this._minutevalue === undefined //the 2 Values received must have values or be undefined at the same time
126-
||
127-
this._hourvalue !== undefined && this._minutevalue !== undefined))
128-
}
120+
129121
}

0 commit comments

Comments
 (0)