Skip to main content

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/PM format.

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 TimeValue parameter.
  • 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 timeValue string using regex.
  • Assigns parsed values to internal state variables.

UI Rendering (renderControl Method)

  • Creates a wrapper div element.
  • 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 the timeValue string 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

Popular posts from this blog

Comparison: Using Workflows vs. JavaScript vs. Plugins in Dynamics CRM?

  There are three ways to automate actions in Microsoft Dynamics CRM: workflows, JavaScript, or plugins. In this blog we will discuss the difference between them and how to choose which option is appropriate for your task. Workflows  can perform tasks such as updating data or sending email. They are triggered by saving records, creating records, or changing specific fields on a form, and once triggered, they run on their own in the background. As you can see in the example of  How to Assign a Territory to a Lead in Dynamics CRM , you can even look up data in another entity. JavaScript  runs on the screen while the user is using a form. JavaScript is triggered by events within the page, updating a field or saving, and it is commonly used to hide or show different fields on the forms. You can also, for instance,  Populate a CRM 2011 Lookup or PartyList Field Using JavaScript  by having a lookup automatically linked to the record based on what is entered in an...

Trigger JavaScript on Click of Button PCF Control

  Overview The TriggerJavascript control is a custom PCF (PowerApps Component Framework) control that renders a button with customizable label, icon, and on-click script execution. The control allows users to dynamically trigger JavaScript code upon clicking the button. Dependencies IInputs, IOutputs from ./generated/ManifestTypes (Auto-generated types from PowerApps) CSS styling from ./CSS/TriggerJavascript.css Class: TriggerJavascript This class implements ComponentFramework.StandardControl<IInputs, IOutputs> and manages rendering a button inside a container, dynamically executing JavaScript code on button click. Properties Private Properties _container: HTMLDivElement - A reference to the container element where the button will be rendered. Methods constructor() Initializes a new instance of the TriggerJavascript control. init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLD...

Task Activity Timeline

  1. Overview The PCF Calendar Control is a custom PowerApps component that displays activities in a calendar-like view. It supports multiple views (monthly, weekly, yearly, daily), allows users to expand/collapse records for each date, and provides a scrollable interface for better usability. The control is built using TypeScript and CSS, adhering to best practices for type safety and maintainability. 2. Features View Modes: Monthly View : Groups activities by month. Weekly View : Groups activities by week. Yearly View : Groups activities by year. Daily View : Displays activities for individual days. Expand/Collapse Functionality: Users can click on a date to expand or collapse its associated records. Smooth animations enhance the user experience. Scrollable Container: A scrollable container ensures that large datasets are manageable. Responsive Design: The control adjusts its layout for smaller screens. Type Safety: The code uses TypeScript interfaces to avoid the use of any and...