BASuite
BAFormElement
A dynamic form builder that renders various input types based on a configurable schema. Supports validation, masking, custom body content, loading states, disabled mode, save button alignment, and full two-way model binding.
Example:
"use client";
import { BAFormElement, BAPera, formElement } from "basuite";
import { useState } from "react";
export default function Playground() {
const [model, setModel] = useState({
inputField: "Sample Text",
firstName: "Muhammad",
lastName: "Ahmed",
cnic: "4210119738169",
password: "123456",
email: "",
datePickerField: "2025-01-01",
selectField: 1,
radioField: "female",
checkboxField: false,
booleanField: false,
textareaField: "Sample Text",
buttonField: undefined,
customBodyField: undefined,
headingField: "Sample Text",
textField: "Sample Text",
dragFileField: null,
imageUploadField: null,
});
const elem: formElement[] = [
{ elementType: "input", col: 4, key: "firstName", label: "First Name" },
{ elementType: "input", col: 4, key: "lastName", label: "Last Name" },
{
elementType: "input",
col: 4,
key: "cnic",
label: "CNIC",
inputType: "maskinput",
mask: "#####-#######-#"
},
{
elementType: "input",
col: 4,
key: "email",
label: "Email",
inputType: "emailinput"
},
{
elementType: "input",
col: 4,
key: "password",
label: "Password",
inputType: "passwordinput"
},
{
elementType: "datepicker",
col: 4,
key: "datePickerField",
label: "Date Picker"
},
{
elementType: "select",
col: 4,
key: "selectField",
label: "Select Field",
showSearch: true,
options: [
{ label: "Opt 1", value: 1 },
{ label: "Opt 2", value: 2 },
{ label: "Opt 3", value: 3 }
]
},
{
elementType: "radio",
col: 4,
key: "radioField",
label: "Radio Field",
options: [
{ label: "Female", value: "female" },
{ label: "Male", value: "male" }
]
},
{ elementType: "checkbox", col: 4, key: "checkboxField", label: "Checkbox Field" },
{ elementType: "boolean", col: 4, key: "booleanField", label: "Boolean Field" },
{ elementType: "textarea", col: 4, key: "textareaField", label: "Textarea Field" },
{ elementType: "button", col: 4, key: "buttonField", label: "Button Field" },
{
elementType: "custombody",
col: 4,
key: "customBodyField",
label: "Custom Body",
body: <BAPera>Custom Body</BAPera>
},
{ elementType: "heading", col: 4, key: "headingField", label: "Heading" },
{ elementType: "text", col: 4, key: "textField", label: "Text Block" }
];
return (
<BAFormElement
model={model}
setModel={setModel}
formElement={elem}
saveButtonLabel="Register"
saveButtonAlignment="start"
/>
);
}
Props:
| Name | Type | Description | Default |
|---|---|---|---|
| model | any | Object containing current values of all form fields. Each key must match a form element key. | |
| setModel | (value: any) => void | Function used to update form field values. BAFormElement calls this when inputs change. | |
| formElement | formElement[] | Array of field configurations defining how each form control is displayed. | |
| onSaveClick | () => void | Callback fired when the save button is clicked and validation passes. | |
| saveLoader | boolean | Shows loading spinner on the save button. | false |
| disabledForm | boolean | Disables all inputs and interactions inside the form. | false |
| loading | boolean | Shows skeleton loaders for all form fields. | false |
| customButton | React.ReactNode | Allows replacing the default save button with a custom button. | |
| hideButton | boolean | Hides the save button entirely. | false |
| disabledSaveButton | boolean | Disables the save button manually. | false |
| apiFunctions | any | Optional API function mapper passed down to fields like lookup. | |
| saveButtonLabel | string | Button label for the form submit action. | "Save" |
| saveButtonIcon | any | Optional icon for the save button. | |
| saveButtonAlignment | "start" | "center" | "end" | Alignment of the save button inside the footer | "end" |
| saveButtonType | "primary" | "default" | "dashed" | "link" | "text" | Ant Design button type for the save button. | "primary" |
formElement:
| Name | Type | Description | Optional |
|---|---|---|---|
| col | 1 | 1.5 | 2 | ... | 12 | Column span size (1–12) used for grid layout. | |
| elementType | "input" | "datepicker" | "select" | "radio" | "checkbox" | "boolean" | "textarea" | "button" | "custombody" | "heading" | "text" | Determines which component will be rendered. | |
| key | string | Unique model key used to bind the field value. | |
| label | string | Label displayed above the form element. | |
| placeholder | string | Placeholder text for inputs and textareas. | |
| textAlign | "left" | "right" | "center" | Text alignment inside the field. | |
| inputType | "numericinput" | "maskinput" | "passwordinput" | "otpinput" | "emailinput" | Type of input component to render. | |
| mask | string | Mask pattern for mask inputs. | |
| lenght | number | Length limit for OTP or masked fields. | |
| otpMark | string | Optional prefix/suffix marker used in OTP input. | |
| fillObjName | string | Parent object key to fill from an API result. | |
| api | string | API endpoint for lookup/select fields. | |
| fillObj | any | Object returned from API responses used to fill data. | |
| valueField | string | Field name to use as value in lookup or select components. | |
| options | { value: any, label: string, disabled?: boolean }[] | Options for select, radio, and checkbox groups. | |
| ChangeEv | any | Custom onChange event handler. | |
| onCancel | any | Cancel event for modal-based fields. | |
| blurEv | any | Blur event handler. | |
| focusEv | any | Focus event handler. | |
| required | boolean | Marks the field as required for validation. | |
| removeDecimals | boolean | Removes decimals for numeric inputs. | |
| isHide | boolean | Hides the field from UI. | |
| multiple | boolean | Allows multiple selection for select input. | |
| maxlength | number | Maximum character length. | |
| disabled | boolean | any | Disables the field. | |
| loading | boolean | Shows a loading state for selects/lookups. | |
| showSearch | boolean | Enables search inside dropdown selects. | |
| onClick | any | Click event handler for button or custom fields. | |
| body | any | React Node used for custombody component. | |
| controller | any | External controller for lookup / async components. | |
| type | any | Custom field type used for dynamic rendering. | |
| apiParams | any | Parameters passed to API calls. | |
| config | any | Extra configuration for component behavior. | |
| displayField | any | Field name used to display item label. | |
| singleValue | any | Used for single-value selects with custom objects. | |
| className | string | Custom CSS class applied to the grid column. | |
| multiSelect | boolean | Enables multi-select dropdown behavior. | |
| arrKey | string | Nested object key for multi-value structures. | |
| validatePeriod | boolean | Validates date range or month/year periods. | |
| data | any | Extra data for select, lookup, or custom components. | |
| showTime | boolean | Enables time selection in datepicker. | |
| validateCodeKey | string | Field key for matching verification codes. | |
| validateController | string | Controller used for validating dependent fields. | |
| fieldAlias | string | Alias used for renaming fields in payloads. | |
| reqFields | string[] | Conditionally required fields list. | |
| useLookup | boolean | Enables lookup component instead of regular select. | |
| aliasModel | { actualKey: string; modelKey: string }[] | Maps multiple model fields to a single API field. | |
| params | any | Additional params for lookup API or computation. |