Inputs Field "Switchboard"

a.k.a Form

Forms are configured using serializable data structures.

Consider, a simple text control:

{
  "type": "text",
  "name": "name",
  "label": "Your Name"
}

Now, add some validation (provided by RHF Options):

{
  "type": "text",
  "name": "name",
  "label": "Your Name",
  "options": {
    "required": "Name is required",
    "maxLength": {
      "value": 20,
      "message": "Name is too long"
    }
  }
}

Using regex for pattern validation (sill serializable!):

{
  "type": "text",
  "name": "name",
  "label": "Your Name (no numbers!)",
  "options": {
    "pattern": {
      "value": "/^[A-Za-z]+$/i",
      "message": "Name must be alphabetic"
    }
  }
}

With more available types:


type SwitchInputType = 
  "text" |
  "password" |
  "multiline" |
  "number" |
  "email" |
  "checkbox" |
  "select" |
  "radio" |
  "switch" |
  "media" |
  "date"

And loads of options:


export type SwitchInputField = {
  type: SwitchInputType;
  name: string;
  defaultValue?: string | number | boolean;
  label?: string;
  realtime?: boolean; 
  placeholder?: string;
  help?: {
    text?: string;
    linkUrl?: string;
    linkText?: string;
  };
  disabled?: boolean;
  hidden?: boolean;
  width?: Width;
  previewType?: "hero" | "thumb" | "attachment";
  options?: SerializableOptions;
  choices?: Choice[];
};

Preview

Try me! Fill out the fields. Also check the console for updates.

Makes the entire form reactive to changes in the fields. When this is turned off, only realtime:true fields will be watched for in the onChange callback.

Note, this is a 'realtime' field, so it will log to the console on change

This field is disabled, so you can't interact with it

You can only choose one, so choose wisely

Note, you can scroll through this dropdown

If you need some inspiration, read this help text

Switches are cool 😎, but data roaming is usually not.

To continue, you must accept

the terms.

Submit the form to see submitted data here.