LetsForm properties

LetsForm API Reference

The <LetsForm /> components accepts the following parameters (all frameworks):

FieldTypeDescription
classNamestringClass name for the LetsFrom main container
customReact viewCustom React view shown next to the form buttons
contextobjectVariables to store in the form context and availabe in scrips
defaultValuesobjectInitial values of the form
disabledbooleanIf true, disable the entire form. Default is false
disableButtonsbooleanDisable submit and cancel buttons
disableOnSubmitbooleanDisable the form on submit (if connectors are specified)
formLetsForm JSON SchemaThe JSON definition of the form
footerReact viewCustom React view shown at the end of the form, just above submit button
hideCancelbooleanHide cancel button
hideSubmitbooleanHide submit button
loaderReactNodeReact component to show while loading external components
localestringLocale for the form (i.e., it-IT, en-US, etc. or auto for auto detect). Default: auto
onChangefunctionCalled when form data changes, argument is an object with the form values
onErrorfunctionCalled when user clicks on "submit" button with validation errors, argument is an object of validation errors
onEnterfunctionCalled when user hits "Enter" on any text field
onSubmitfunctionCalled when user clicks on "submit" button and there are no validation error, argument is an object with the form values
onSubmitSuccessfunctionCalled after the form was succesfully submitted (if connectors are specified). The argument it's generally the response object of the fetch call, it's an array in case of multiple connectors
onSubmitErrorfunctionCalled if a connector defined in the form fails with an excpetion or a 4xx / 5xx response. The argument is the error object or the response object from the fetch call
onJavascriptErrorfunctionCalled when JavaScript code embedded in the form (a Transformer of validator), raises an error. Argument is an object describing the error
plaintextbooleanShow the plaintext version of the form. Default is false
prealoadComponentsbooleanPreaload all external components before showing the form. Default: true
readOnlybooleanPut the fields of the form in read only mode. Default is false
resetAfterSubmitbooleanReset form on a succesfully submit (if connectors are specified)

For example:

import LetsForm from 'lets-form/react-rsuite5';
 
<LetsForm
  defaultValues={myDefaultValues}
  locale="en-US"
  form={myFormSchema}
  onChange={values => {
    setState(values);
  }}
  onSubmit={async values => {
    await postDataToMyServer(values);
  }}
/>

Note that there are different builds of the <LetsForm /> component optimized for the specific framework (i.e., import LetsForm from 'lets-form/react-bootstrap' for React Bootstrap)

LetsForm JSON schema

The LetsForm JSON form schema describes the form (fields, validation, etc.)

FieldTypeDescription
versionstringVersion of LetsForm. Always "1"
layoutstringThe layout of the form: horizontal, vertical, inline
disabledbooleanDisable the entire form (all fields and buttons)
readOnlybooleanSet the form in read-only mode
plaintextbooleanSet the form in plaintext mode, useful for confirmations
locales[string]Supported locales by the form (i.e., ['it-IT', 'en-US'])
fields[LetsFormField]An array of fields definitions
labelSubmitstringLabel for submit button. Default: Submit
labelCancelstringLabel for cancel button. Default: Cancel
buttonsAlignstringButtons alignment: left, right, center

For example:

{
  "$schema": "https://unpkg.com/lets-form/schemas/react-rsuite5/form.json",
  "version": "1",
  "layout": "horizontal",
  "disable": false,
  "readOnly": false,
  "plaintext": false,
  "locales": ["it-IT", "en-US"],
  "fields": [ ... ]
}

Use the $schema property to validate the schema, many modern code editors (i.e. Visual Studio Code) use the JSON schema to help auto-completing the JSON. The preferred way to build the JSON form schema is using LetsForm Designer (opens in a new tab).

LetsForm field

Fields are the smallest building block of LetsForm, the following are the common properties for all fields. More properties are available based on the component key

FieldTypeDescription
namestringThe name of the field, the value. Must be unique within the form
labelstring | i18nThe visual label of the field
hintstring | i18nShow a small help for this field, it's generally shown below the input field (but some frameworks may show it in a different way)
requiredbooleanMark the field as required. Each UI framework has a different way of visually marking a field as required
componentstringThe field type (i.e., input-text). Each component has a different set of parameters, see the list below

See the complete list of parameters for each component: input-text, toggle, select, group, two-columns, three-columns, columns, array, input-number, slider, date, checkbox, checkbox-group, radio-group, input-tag, input-mask, textarea, rate, placeholder, multiselect, placeholder-image, button, divider, datetime, tabs, radio-tile, upload, buttons-toggle-group, steps, esm-module, time, hidden.

For example:

{
  "component": "input-text",
  "name": "my_field",
  "label": "My Field",
  "hint": "Some help for this field"
}

Some field properties are UI framework specific (i.e., valid for RSuite but not for Material UI), these can be either specified in the root of the field object or in a sub-keys like in the example below block is the sub-key react-rsuite5.

Forms exported by LetsForm Designer will always use framework specific sub-keys.

A complete example of a LetsForm JSON scheme

my_form.json
{
  "$schema": "https://unpkg.com/lets-form/schemas/react-rsuite5/form.json",
  "version": 1,
  "layout": "vertical",
  "validationMode": "onSubmit",
  "fluid": true,
  "fields": [
    {
      "component": "text-input",
      "label": "My Text",
      "name": "my_field",
      "hint": "Some help can be useful"
    },
    {
      "component": "select",
      "label": "My Select",
      "name": "my_select",
      "options": [
        {
          "value": "one",
          "label": "One"
        },
        {
          "value": "two",
          "label": "Two"
        }
      ],
      "react-rsuite5": {
        "block": true
      }
    }
  ]
}

LetsForm methods

<LetsForm/> component also exposes some methods that can be call in an imperative way

MethodReturn TypeDescription
validateobjectTriggers programmatically the form validation, returns a validation object (see React Hook Form)

For example

const MyView = () => {
  const ref = useRef();
 
  return (
    <>
      <LetsForm
        form={MY_FORM}
        ref={ref}
      />
      <input
        type="button"
        onClick={async () => {
          // trigger validation programmatically
          if (!await ref.current.validate()) {
            return;
          }
          // do something
        }}
      />
    </input>
  );
};