Time Picker PCF Control
Overview
The TimePickerControl is a custom PowerApps component built using TypeScript and HTML. It provides an interactive time selection interface with both digital and analog (clock face) inputs, enabling users to select and modify time values conveniently.
Features
- Editable hour and minute selection.
- AM/PM toggle support.
- Analog clock face for hour selection.
- Interactive UI updates on selection.
- Reset to default time option.
- Outputs the selected time in
hh:mm AM/PMformat.
Implementation Details
Initialization (init Method)
The init method initializes the control:
- Retrieves the existing time value from the context parameters.
- Parses the time value to extract hour, minute, and AM/PM settings.
- Calls
renderControl()to construct the UI elements.
View Updates (updateView Method)
- Detects changes in the
TimeValueparameter. - Updates the internal state if a new value is provided.
- Calls
refreshUI()to reflect changes in the UI.
Time Parsing (parseTimeValue Method)
- Extracts hour, minute, and AM/PM components from the
timeValuestring using regex. - Assigns parsed values to internal state variables.
UI Rendering (renderControl Method)
- Creates a wrapper
divelement. - Calls helper methods to generate different UI sections:
- Time Input Section: Displays editable hour, minute, and AM/PM toggle buttons.
- Clock Section: Renders a circular clock face with hour buttons.
- Footer Buttons: Provides CANCEL (reset) and OK (confirmation) buttons.
- Appends the wrapper to the container element.
Time Input Handling
createEditableSpan(): Creates editable<span>elements for hour and minute fields.createToggleButton(): Generates AM/PM toggle buttons.updateTimeValue(): Updates thetimeValuestring and notifies the framework of the change.
Clock Face Interaction
createClockSection(): Constructs a clock face with hour buttons.createHourButton(): Places hour buttons at calculated positions on the clock face.- Clicking an hour button updates the selected hour and refreshes the UI.
User Interaction
toggleAMPM(): Toggles between AM and PM.refreshUI(): Re-renders the control to reflect updates.resetToDefault(): Resets to the default time (07:00 AM).
Output Handling (getOutputs Method)
Returns the selected time in hh:mm AM/PM format as TimeValue.
Cleanup (destroy Method)
Clears the control’s container when the component is removed.
Usage
The TimePickerControl is suitable for scenarios requiring an intuitive and interactive time selection interface in PowerApps applications. It ensures an improved user experience by combining both manual input and visual selection elements.
Comments
Post a Comment