Form fields

Input fields

Text, email, password, number, date, phone with a mask, color and checkbox inputs.

InputField

InputField draws an <input>. Pick the kind with props.type: text (default), email, password, number, date, tel, color, checkbox, ...

Every field needs a name — it is the key of its value. label and placeholder are the texts. uppercase / lowercase change letters while typing, and mask formats digits (# = one digit).

Try it

Loading example…
Events0
Use the example — every action it runs shows up here with its data.

Code

Copy Full page.js into app/your-page/page.js of a Next.js app (withrcube-html, react-bootstrap and Bootstrap's CSS installed) — it runs as is. Or copy only the schema and keep your own page.

[
  {
    "type": "row",
    "id": "row-1",
    "children": [
      {
        "type": "column",
        "id": "c-text",
        "props": {
          "className": "col-12 col-md-6"
        },
        "children": [
          {
            "type": "InputField",
            "id": "full-name",
            "props": {
              "name": "fullName",
              "label": "Full name (uppercase)",
              "placeholder": "Jane Doe",
              "uppercase": true,
              "onChange": "fieldChanged()"
            }
          }
        ]
      },
      {
        "type": "column",
        "id": "c-email",
        "props": {
          "className": "col-12 col-md-6"
        },
        "children": [
          {
            "type": "InputField",
            "id": "email",
            "props": {
              "type": "email",
              "name": "email",
              "label": "Email (lowercase)",
              "lowercase": true,
              "onChange": "fieldChanged()"
            }
          }
        ]
      },
      {
        "type": "column",
        "id": "c-password",
        "props": {
          "className": "col-12 col-md-6"
        },
        "children": [
          {
            "type": "InputField",
            "id": "password",
            "props": {
              "type": "password",
              "name": "password",
              "label": "Password",
              "onChange": "fieldChanged()"
            }
          }
        ]
      },
      {
        "type": "column",
        "id": "c-phone",
        "props": {
          "className": "col-12 col-md-6"
        },
        "children": [
          {
            "type": "InputField",
            "id": "phone",
            "props": {
              "type": "tel",
              "name": "phone",
              "label": "Phone (mask)",
              "mask": "(###) ###-####",
              "placeholder": "(555) 123-4567",
              "onChange": "fieldChanged()"
            }
          }
        ]
      },
      {
        "type": "column",
        "id": "c-number",
        "props": {
          "className": "col-6 col-md-3"
        },
        "children": [
          {
            "type": "InputField",
            "id": "quantity",
            "props": {
              "type": "number",
              "name": "quantity",
              "label": "Quantity",
              "min": 1,
              "max": 10,
              "onChange": "fieldChanged()"
            }
          }
        ]
      },
      {
        "type": "column",
        "id": "c-date",
        "props": {
          "className": "col-6 col-md-3"
        },
        "children": [
          {
            "type": "InputField",
            "id": "start",
            "props": {
              "type": "date",
              "name": "startDate",
              "label": "Start date",
              "onChange": "fieldChanged()"
            }
          }
        ]
      },
      {
        "type": "column",
        "id": "c-color",
        "props": {
          "className": "col-6 col-md-3"
        },
        "children": [
          {
            "type": "InputField",
            "id": "theme",
            "props": {
              "type": "color",
              "name": "themeColor",
              "label": "Color",
              "onChange": "fieldChanged()"
            }
          }
        ]
      },
      {
        "type": "column",
        "id": "c-check",
        "props": {
          "className": "col-6 col-md-3 d-flex align-items-center"
        },
        "children": [
          {
            "type": "InputField",
            "id": "agree",
            "props": {
              "type": "checkbox",
              "name": "agree",
              "label": "I agree",
              "onChange": "fieldChanged()"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "row",
    "id": "row-result",
    "children": [
      {
        "type": "column",
        "id": "col-result",
        "children": [
          {
            "type": "P",
            "id": "result",
            "props": {
              "className": "alert alert-secondary py-2 small mb-0",
              "text": "Change any field."
            }
          }
        ]
      }
    ]
  }
]

Options used here

OptionWhat it does
typetext, email, password, number, date, tel, color, checkbox, radio, range, ...
nameKey of the value (defaults to the node id).
label / placeholderTexts shown with the field.
uppercase / lowercaseConvert letters while typing.
maskFormat digits while typing: "(###) ###-####", "####-####-####-####".
min / maxNumber range (checked on Submit, see Validation).
disabled / readOnlyNormal input attributes are passed through.

Events

EventWhen it runsYour action receives
onChangeEvery edit.(event, { name, value }) — value is true / false for a checkbox.
onBlur / onFocus / onKeyDownFocus leaves / arrives, a key is pressed.(event, { name, value })