restrictInputWithCounter
Wires a live character counter to an input/textarea, and (depending
on options) restricts further input once the limit is reached.
Returns: any
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
inputElement | `HTMLInputElement \ | HTMLTextAreaElement` | required | - |
counterContainer | HTMLElement | required | - | The element that displays the current/remaining character count. |
options | any | optional | {} | Configuration such as the max length and counter display format. Defaults to {}. |
Usage
Example: Use restrictInputWithCounter
const inputElement = document.getElementById('additionalInfo');
const counterContainer = document.getElementById('counterContainer');
const options = {
maxLength: 150,
minLength: 10,
shouldButtonDisable: true,
formId: 'myForm'
};
nfsfu234FormValidation.restrictInputWithCounter(inputElement, counterContainer, options);Last updated on