Registry UI Widgets: Complete guide and reference

Learn how to build dynamic forms from JSON configurations using the OpenG2P Registry UI Widgets library. This comprehensive guide covers everything from basic setup to advanced customization, includin

Table of contents


Introduction

The OpenG2P Registry UI Widgets library is a powerful, extensible React component library designed for building dynamic forms from JSON configurations. It provides:

  • 19+ Pre-built Widgets for common form inputs

  • Redux-based State Management for centralized form state

  • Flexible Data Binding with dot-notation paths

  • Comprehensive Validation with built-in rules and Zod schemas

  • Conditional Logic for dynamic form behavior

  • Multiple Data Sources (static, API, schema references)

  • Internationalization support

  • Extensible Architecture for custom widgets


Installation and setup

Step 1: Install the package

Step 2: Install peer dependencies

Step 3: Basic setup

Create a Redux store and wrap your application with WidgetProvider:


Core concepts

1. Widget configuration

Widgets are configured using JSON objects that follow the BaseWidgetConfig interface. Every widget requires:

  • widget: The widget name/type (e.g., "text", "select", "date")

  • widget-id: A unique identifier for the widget

  • widget-type: The type category ("input", "layout", "table", "group")

2. useBaseWidget Hook

The useBaseWidget hook is the foundation of every widget. It provides:

3. Widget registry

The widget registry is a plugin system that maps widget names to React components. Widgets must be registered before use:

The library automatically registers all default widgets when imported.


Basic usage

Rendering a single widget

Rendering multiple widgets with layout

Using sections and panels

For complex forms, use the sections-based structure:


Widget Configuration

Basic configuration properties

Data path examples:

  • Single path: "widget-data-path": "person.name"

  • Multi-path: "widget-data-path": { "firstName": "person.fname", "lastName": "person.lname" }

Example: complete text input configuration


Data binding

Single path binding

Bind a widget to a single data path:

This binds the widget to data.person.name.

Multi-path binding

Bind a widget to multiple data paths (useful for complex widgets):

The widget receives an object with these properties.

Accessing data

The useBaseWidget hook automatically handles data binding. The value property contains the bound data:

Getting other field values

Use getFieldValue to access other widget values:


Validation

Built-in validation rules

Predefined validation types

Custom regex patterns

Zod schema validation

For complex validation logic, use Zod schemas:

Validation example: email with custom rules

Manual validation

You can manually set errors:


Conditional Logic

Show/hide widgets

Show or hide widgets based on other field values:

Enable/disable widgets

Enable or disable widgets based on conditions:

Available operators

  • equals - Field equals value

  • notEquals - Field does not equal value

  • notEmpty - Field is not empty

  • empty - Field is empty

  • greaterThan - Field is greater than value

  • lessThan - Field is less than value

  • contains - Field contains value (for strings/arrays)

  • notContains - Field does not contain value

Complex conditional example


Data sources

Data sources provide options for select, radio, and checkbox widgets.

Static data source

Pre-defined option arrays:

API Data Source

Load options from a REST API:

Dependent API data source

Load options based on another field's value:

Schema reference data source

Reference data from your schema:

API adapter setup

Provide a custom API adapter for API data sources:


Formatting

Date formatting

Currency formatting

Number formatting

Text formatting

Phone number formatting


Widget reference

This section provides detailed documentation for each widget available in the library. Each widget includes configuration options, usage examples, and special features.

Note on Configuration:

  • widget-data-path can be:

    • Single path (string): "widget-data-path": "person.name"

    • Multi-path (object): "widget-data-path": { "firstName": "person.fname", "lastName": "person.lname" }

  • widget-data-default accepts different types depending on the widget:

    • Text/TextArea/Phone: string (e.g., "default value")

    • Number/Currency: number (e.g., 0 or 100.50)

    • Boolean: boolean (e.g., true or false)

    • Date: string in ISO format (e.g., "2024-01-15") or "today"

    • DateTime: string in ISO format (e.g., "2024-01-15T10:30:00") or "now"

    • Select/Radio: string or number matching option values (e.g., "option1" or 1)

    • Checkbox (single): boolean (e.g., false)

    • Checkbox (multiple): array of strings (e.g., ["sports", "music"])

    • Array/Table: array of values (e.g., [] or ["item1", "item2"])

Input widgets

1. Text Input Widget (text)

A versatile text input widget supporting various input types and advanced formatting options.

Widget name: text Widget type: input

Configuration options:

Basic example:

Advanced Example with Formatting:

Email input example:

Special features:

  • Character type filtering (alphabetic, alphanumeric, numeric, etc.)

  • Case transformation (lowercase, uppercase, capitalize)

  • Input masking for phone numbers, IDs, etc.

  • Live character counter

  • Multiple HTML input types


2. Text Area Widget (textarea)

Multi-line text input widget for longer text content.

Widget name: textarea Widget type: input

Configuration options:

Example:

Special features:

  • Configurable number of rows (default: 2)

  • Character counter support

  • Same character filtering and case control as text input


3. Number Input Widget (number)

Numeric input widget with decimal precision, formatting, and range validation.

Widget name: number Widget type: input

Configuration options:

Integer example:

Currency example:

Special features:

  • Integer or decimal number support

  • Configurable decimal precision (0-6 places)

  • Rounding or truncation modes

  • Thousand and decimal separators

  • Right-aligned by default (configurable)

  • Format on blur option


4. Currency Input Widget (currency)

Specialized widget for currency input with automatic formatting.

Widget name: currency Widget type: input

Configuration options:

Similar to Number Input Widget, but optimized for currency values.

Example:


5. Phone Input Widget (phone)

Specialized widget for phone number input with automatic formatting.

Widget name: phone Widget type: input

Configuration options:

Example:


6. Date Input Widget (date)

Date input widget with picker support and date constraints.

Widget name: date Widget type: input

Configuration options:

Date of birth example:

Special features:

  • Multiple date formats (YYYY-MM-DD, DD/MM/YYYY, etc.)

  • Date picker, manual input, or hybrid mode

  • Date constraints (past-only, future-only)

  • Min/max date validation

  • Default to today option


7. DateTime Input Widget (datetime)

Date and time input widget with picker support.

Widget name: datetime Widget type: input

Configuration options:

Example:


8. File Input Widget (file)

File upload widget with preview support and file validation.

Widget name: file Widget type: input

Configuration options:

Single file example:

Multiple files example:

Special features:

  • Single or multiple file upload

  • File type restrictions via accept attribute

  • File size validation

  • File preview for images and PDFs

  • File serialization for Redux store


Selection widgets

9. Select Widget (select)

Dropdown/select widget with data source support.

Widget name: select Widget type: input

Configuration options:

Static options example:

API data source example:

Special features:

  • Static, API, or schema data sources

  • Dependent data sources (reload based on other fields)

  • Option sorting

  • Loading state for API sources


10. Radio Widget (radio)

Radio button group widget for single selection.

Widget name: radio Widget type: input

Configuration options:

Example:

Special features:

  • Vertical, horizontal, or grid layout

  • Same data source support as select widget

  • Option sorting


11. Checkbox Widget (checkbox)

Checkbox widget for boolean or multiple selections.

Widget name: checkbox Widget type: input

Configuration options:

Single checkbox (boolean) example:

Multiple checkboxes example:

Special features:

  • Single checkbox for boolean values

  • Multiple checkboxes for array selections

  • Same layout options as radio widget


12. Boolean Widget (boolean)

Specialized boolean widget with multiple representation options.

Widget name: boolean Widget type: input

Configuration options:

Checkbox example:

Radio buttons example:

Toggle/switch example:

Special features:

  • Multiple representation styles (true/false, yes/no, on/off, custom)

  • Multiple control types (checkbox, radio, toggle)

  • Optional unset state

  • Custom labels support


Layout widgets

13. Array Widget (array-widget)

Widget for repeating simple values in an array.

Widget name: array-widget Widget type: group

Configuration options:

Example:

Special features:

  • Dynamic add/remove items

  • Configurable item widget

  • Array value storage


14. Iterable Accordion Widget (iterable-accordion)

Accordion-style widget for repeating complex objects.

Widget name: iterable-accordion Widget type: group

Configuration options:

Similar to Array Widget, but displays items in an accordion format.

Example:

Special features:

  • Accordion UI for better organization

  • Supports complex nested widgets

  • Collapsible items


Display widgets

15. Display Widget (display)

Read-only widget for displaying information.

Widget name: display Widget type: input

Configuration options:

Example:

Special features:

  • Read-only display

  • Supports formatted values

  • Can display without label (paragraph text)


16. Profile Widget (profile)

Widget for displaying profile information in a card layout.

Widget name: profile Widget type: input

Configuration options:

Example:


Table widgets

17. Table Widget (table)

Full-featured table widget with editable cells.

Widget name: table Widget type: table

Configuration options:

Example:

Special features:

  • Editable cells with widget support

  • Add/remove rows

  • Column-specific widget types

  • Full validation support per column


18. Simple Table Widget (simple-table)

Simplified table widget for read-only or simple data display.

Widget name: simple-table Widget type: table

Configuration options:

Similar to Table Widget but optimized for display purposes.

Example:


Widget configuration summary

All widgets support these common configuration properties:

  • widget: Widget name/type (required)

  • widget-type: Widget category - 'input', 'layout', 'table', or 'group'

  • widget-id: Unique identifier (required)

  • widget-label: Display label

  • widget-data-path: Data binding path

  • widget-data-default: Default value

  • widget-required: Required field flag

  • widget-readonly: Read-only flag

  • widget-data-placeholder: Placeholder text

  • widget-data-helptext: Help text

  • widget-data-tooltip: Tooltip text

  • widget-data-validation: Validation rules

  • widget-data-format: Formatting options

  • widget-data-source: Data source configuration

  • widget-data-options: Conditional logic and widget-specific options


Creating custom widgets

Step 1: Create the widget component

Step 2: Register the widget

Step 3: Use the widget

Advanced custom widget example


Advanced patterns

Multi-step forms

Dynamic form generation

Form validation on submit

Array widgets


Internationalization

The widget library supports internationalization (i18n) with automatic translation loading from your host project's locale files. By default, the library will automatically discover and load translations from your project's messages/locales folder, making it easy to integrate with existing i18n setups.

Automatic translation loading (default behavior)

The library automatically loads translations from your host project's locale directory. You don't need to configure anything - just place your translation files in one of these standard locations (checked in order):

  • /messages/{language}.json

  • /public/messages/{language}.json

  • /i18/locales/{language}.json

  • /public/i18/locales/{language}.json

  • /locales/{language}.json

  • /public/locales/{language}.json

  • /locales/{language}/translation.json

  • /public/locales/{language}/translation.json

Example project structure:

Translation file format (public/locales/en.json):

The library will automatically:

  1. Detect the current language (defaults to 'en')

  2. Try to load translations from the standard paths listed above

  3. Fall back to default English translations if no files are found

  4. Use the loaded translations for all widget labels and messages

No configuration needed! Simply use the widgets and they will automatically pick up translations from your project's locale files.

Override methods

All methods below are overrides to the automatic loading behavior. Use them when you need custom translation logic or want to provide translations programmatically.

Method 1: Manual initialization with custom resources

If you want to provide translations programmatically instead of using files:

Method 2: Custom load path

If your translation files are in a non-standard location:

Method 3: Using translate prop in WidgetProvider

You can provide a custom translation function that overrides the default behavior:

Method 4: Translating widget labels programmatically

For translating UI schema labels before rendering:

Using translation in custom widgets

Summary

  • Default behavior: Automatically loads translations from your project's locales/ or public/locales/ folder

  • No setup required: Just place your translation files in standard locations

  • Override methods: Use manual initialization, custom paths, or translate props when you need custom behavior

  • Fallback: Falls back to default English translations if no files are found


Best practices

1. Widget IDs

Always use unique, descriptive widget IDs:

2. Data paths

Use consistent dot-notation paths:

3. Validation

Provide clear, user-friendly error messages:

4. Conditional logic

Keep conditions simple and testable:

5. Data sources

Cache API responses when possible:

6. Performance

  • Use React.memo for expensive widget components

  • Avoid unnecessary re-renders by using stable references

  • Use useMemo for computed values

7. Type safety

Always use TypeScript types:


Troubleshooting

Widget not rendering

Problem: Widget doesn't appear on screen.

Solutions:

  1. Check if widget is registered:

  1. Check if widget is hidden by conditional logic:

  1. Verify widget configuration:

Validation not working

Problem: Validation errors don't appear.

Solutions:

  1. Ensure widget-required or validation rules are set:

  1. Check if field has been touched:

  1. Manually trigger validation:

Data not updating

Problem: Widget value doesn't update in Redux store.

Solutions:

  1. Verify data path is correct:

  1. Check Redux store state:

  1. Ensure onChange is called:

API data source not loading

Problem: Options from API don't appear.

Solutions:

  1. Verify API adapter is provided:

  1. Check API response format:

  1. Check for errors in console:

Conditional logic not working

Problem: Widget doesn't show/hide based on conditions.

Solutions:

  1. Verify condition field path:

  1. Check field value:

  1. Verify operator:

TypeScript Errors

Problem: TypeScript compilation errors.

Solutions:

  1. Ensure all types are imported:

  1. Check widget registry entry:

  1. Verify config structure:


Conclusion

This tutorial has covered all the essential aspects of the OpenG2P Registry UI Widgets library. You should now be able to:

  • Set up and configure the library

  • Use pre-built widgets effectively

  • Create custom widgets

  • Implement validation and conditional logic

  • Work with data sources and formatting

  • Handle internationalization

  • Troubleshoot common issues

For more examples, check the examples/ directory in the repository. For API reference, see the main README.md file.

Happy coding! 🚀

Last updated

Was this helpful?