Skip to content

R4RD0/Multi-Option-Set-Control

 
 

Repository files navigation

Overview The MultiSelectControl is a PowerApps Component Framework (PCF) control designed to allow users to select multiple records from a dataset within a model-driven app. It retrieves records from a specified entity and field, displaying them as a list of checkboxes. The selected values are stored as a comma-separated string.

Features Retrieves records dynamically using the Web API.

Displays checkboxes with corresponding labels.

Maintains state of selected records.

Handles errors gracefully.

  1. Constructor The constructor initializes default values for entity and field names.

  2. Initialization (init method) Parameters: context: Provides access to environment data.

notifyOutputChanged: Callback function to notify PowerApps of changes.

state: Dictionary object for state persistence.

container: HTML container for rendering the component.

Steps: Initializes private variables.

Creates and styles necessary DOM elements (div, ul, label).

Retrieves and validates entity and field names.

Fetches data using retrieveMultipleRecords.

Renders the retrieved records into a checkbox list.

  1. View Update (updateView method) Updates the component whenever the property bag changes. It extracts and processes the stored comma-separated values.

  2. Output Values (getOutputs method) Returns the selected values as a comma-separated string.

  3. Cleanup (destroy method) Handles component cleanup before removal. Currently, no explicit cleanup is required.

  4. Event Handling (checkBoxChanged method) Handles checkbox selection changes:

Identifies the checkbox state.

Adds/removes the value from the _guidList.

Triggers notifyOutputChanged to update the model-driven app.

  1. Record Rendering (renderRecords method) Creates and appends checkboxes dynamically for each retrieved record.

Extracts entity ID and field value.

Constructs a checkbox and label.

Appends the elements to the unordered list.

  1. Error Handling (handleError method) Logs errors and displays error messages to the user in case of API failures.

  2. Utility Methods createStyledElement: Helper function to create HTML elements with classes and attributes.

getSafeString: Ensures safe extraction of string values from unknown sources.

Dependencies ComponentFramework.Context: Provides access to environment and parameters.

ComponentFramework.WebApi.retrieveMultipleRecords: Fetches data from the model-driven app.

Conclusion The MultiSelectControl is a customizable PCF control that enhances multi-selection capabilities in model-driven apps by dynamically fetching records and allowing users to select multiple values efficiently.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 65.0%
  • CSS 24.7%
  • JavaScript 10.3%