Skip to content

Cleave.js Input Masking Element ​

The Cleave.js element provides formatted input masks for various types of data, such as phone numbers, credit card numbers, dates, and custom patterns. It enhances user experience by guiding input format and providing immediate visual feedback.

In BetterForms, this element is used when you need to enforce a specific input format for a text field.

Note: This element uses type: "cleave" in its schema definition, and its masking behavior is controlled by fieldOptions.

Common Configuration Properties ​

PropertyTypeDescription
typeStringMust be set to "cleave". The Cleave.js functionality is configured through fieldOptions.
labelStringThe label for the input field.
modelStringThe key in your BetterForms data model where the (potentially unmasked) input value will be stored.
placeholderStringPlaceholder text.
disabledBooleanDisables the input.
readonlyBooleanMakes the input read-only.
hintStringHelper text.
requiredBooleanMarks the field as required.
styleClassesString / ArrayCSS classes for styling.
fieldOptionsObjectCrucial property. Options passed directly into new Cleave(...).

Example: Phone Number Mask ​

json
{
  "type": "cleave",
  "label": "Phone Number",
  "model": "phoneNumber",
  "placeholder": "(999) 999-9999",
  "fieldOptions": {
    "phone": true,
    "phoneRegionCode": "US"
  }
}

Example: Date Mask (YYYY-MM-DD) ​

json
{
  "type": "cleave",
  "label": "Date of Birth",
  "model": "dob",
  "placeholder": "YYYY-MM-DD",
  "fieldOptions": {
    "date": true,
    "datePattern": ["Y", "m", "d"],
    "delimiter": "-"
  }
}

Example: Credit Card ​

json
{
  "type": "cleave",
  "label": "Credit Card Number",
  "model": "creditCardNum",
  "fieldOptions": {
    "creditCard": true
  }
}

Klai Studio Specific Notes ​

  • The live field writes back cleave.properties.result when available, or falls back to the input's current value.
  • If you omit settings, the component supplies defaults such as phoneRegionCode: "AU", datePattern: ["d", "m", "Y"], delimiter: " ", and numeralDecimalScale: 2.
  • fieldOptions supports the standard Cleave.js configuration keys such as creditCard, phone, date, numeral, blocks, delimiter, prefix, uppercase, and lowercase.

Full Property Reference ​

This element leverages the Cleave.js library. For the available fieldOptions, refer to:

Klai Studio documentation