1.1.3 • Published 11 months ago

clay-dynamic-forms v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Liferay Clay Form Generator

Introduction

The Liferay Clay Form Generator is a dynamic form generator built for Liferay applications. It allows developers to define form schemas and automatically generate forms with validation, layout, and a variety of input controls.

Features

  • Dynamic form generation from schema
  • Support for various control types: select, checkbox, toggle, radio, date, file, input, slider, and textarea
  • Built-in validation with custom messages
  • Flexible layout configuration

Installation

To install the Liferay Clay Form Generator, run:

npm install clay-dynamic-forms

Usage

Basic Example

import React, { useRef } from 'react';
import { LRDynamicForm, LRDynamicFormRef } from 'liferay-clay-form-generator';

const formSchema = {
    properties: {
        username: {
            name: 'username',
            title: 'Username',
            controlType: 'input',
            dataType: 'text',
            validators: [{ type: 'required', message: 'Username is required' }]
        },
        password: {
            name: 'password',
            title: 'Password',
            controlType: 'input',
            dataType: 'text',
            validators: [{ type: 'required', message: 'Password is required' }]
        }
    }
};

const MyFormComponent = () => {
    const formRef = useRef<LRDynamicFormRef>(null);

    const handleSubmit = () => {
        if (formRef.current) {
            formRef.current.handleFormSubmit();
        }
    };

    return (
        <div>
            <LRDynamicForm schema={formSchema} ref={formRef} />
            <button onClick={handleSubmit}>Submit</button>
        </div>
    );
};

export default MyFormComponent;

Schema Definition

FormField

export interface FormField {
    name: string;
    title: string;
    controlType: 'select' | 'checkbox' | 'toggle' | 'radio' | 'toggle-group' | 'date' | 'file' | 'input' | 'slider' | 'textarea';
    dataType: 'text' | 'boolean' | 'number' | 'object';
    format?: string;
    default?: any;
    enum?: any[];
    config?: any;
    tooltipPosition?: "top" | "bottom";
    [key: string]: any;
}

Sizes

export interface Sizes {
  lg: number;
  md: number;
  sm: number;
  xs: number;
}

LayoutItem

export interface LayoutItem {
  type: 'row' | 'col';
  sizes?: Sizes;
  field: string;
  items?: LayoutItem[];
}

FormSchema

export interface FormSchema {
  properties: {
    [key: string]: FormField;
  };
  layout?: LayoutItem[];
  validation?: FieldValidation[];
}

Validator

export interface Validator {
  type: 'required' | 'pattern';
  pattern?: string;
  message?: string;
}

FieldValidation

export interface FieldValidation {
  field: string;
  validators: Validator[];
}

Props

LRDynamicFormProps

export interface LRDynamicFormProps {
  schema: any;
}

Ref

LRDynamicFormRef

export interface LRDynamicFormRef {
  handleFormSubmit: () => void;
  handleFormReset: () => void;
  handleFormValidation: () => Promise<boolean>;
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any bugs or features.

License

This project is licensed under the MIT License.

1.1.1

11 months ago

1.1.0

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago