Skip to main content

Implement a Star Rating Custom Form Element using a Third Party Library

Implementing a custom form element allows you to augment the existing form elements that come with VertiGIS Studio Workflow.

This article will walk you through creating a form element that uses the react-star-ratings component to allow the user to select up to five stars.


Follow the instructions in the Web Applications SDK page to set up your development environment.


A working knowledge of TypeScript is recommended before extending Workflow for web-based hosts.


Implementing a star rating custom form element for web applications using a third party library consists of the following steps:

  1. Adding third party library dependencies to your project.
  2. Creating the custom form element.
  3. Implementing the custom form element using the third party library.

Adding Dependencies#

  1. Run npm install react-star-ratings in the terminal to install the third party react-star-ratings component.

Set up Custom Form Element Skeleton#

To create a new form element:

  1. Open the Workflow activity SDK in Visual Studio Code.
  2. Run npm run generate in the terminal.
  3. When prompted, select Form Element.
  4. Enter the name of the form element you would like to create and press Enter. For example, StarRating.
  5. Open the newly created src/activities/StarRating.tsx file.

Implement the Custom Form Element#

Modify the skeleton form element implementation in src/activities/StarRating.tsx to match the following example.

import React, { useEffect, useState } from "react";import StarRatings from "react-star-ratings";import {    CustomFormElementProps,    RegisterCustomFormElementBase,} from "@geocortex/workflow/runtime/app/RegisterCustomFormElementBase";
/** * A simple React Component that displays a star rating input. * @param props The props that will be provided by the Workflow runtime. */const StarRating = (props: CustomFormElementProps) => {    const [rating, setRating] = useState(props.element.value);
    // Update the form state when the rating value changes.    const handleRatingChange = (newRating) => {        setRating(newRating);        props.element.value = newRating;        props.raiseEvent("changed", newRating);    };
    // Set local state when the form state changes.    useEffect(() => {        // Provide a default value if no value exists.        setRating(props.element.value ?? 0);    }, [props.element.value]);
    return (        <StarRatings            changeRating={handleRatingChange}            rating={rating}            starDimension="1.5em"            starHoverColor="#ffb400"            starRatedColor="#ffb400"        />    );};
/** * @displayName Register StarRating Form Element * @category Custom Activities * @description Registers a Star Rating form element */export class RegisterStarRatingElement extends RegisterCustomFormElementBase {    /** Perform the execution logic of the activity. */    execute() {        this.register("StarRating", StarRating);    }}

Deploy the Form Element#

Follow the instructions to build and deploy the activity pack.

Test the Form Element#

Once your activity pack is hosted and registered, your Register StarRating Form Element custom activity should appear in the activity toolbox in VertiGIS Studio Workflow Designer alongside the built-in activities.

To use your custom form element in a workflow:

  1. Add your Register StarRating Form Element custom activity to your workflow so that it runs before any Display Form activities that will use the custom form element.
  2. Select the Display Form activity that you want to include your form element in.
  3. Add a Custom form element to the form.
  4. Set the Custom Type property of the Custom form element to StarRating.
  5. Test your workflow.