1.2.5 • Published 5 years ago

input-soft-limit v1.2.5

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Input Soft Limit

A simple JavaScript module that applies a soft character limit to inputs and textareas.

Input Soft Limit can be applied to a collection of inputs and/or textareas, each with their own character limit. If any of the inputs/textareas exceed their character limit, the form's submit button will be disabled.

How to use

Install it as a dependency with npm:

npm i -D input-soft-limit

Import it:

import InputSoftLimit from 'input-soft-limit';

Instantiate it, passing in some settings:

const inputSoftLimitInstance = new InputSoftLimit({
  submitButton: '.submit',
  inputInvalidClass: 'is-invalid'
});

Initialize it:

inputSoftLimitInstance.init();

Add the necessary classes and data attributes to your HTML:

<input type="text"
       class="input-soft-limit"
       id="name"
       data-input-soft-limit="10"
       data-input-soft-limit-counter=".name-count">

<p>Characters remaining: <span class="name-count"></span></p>

HTML attributes

PropertyTypeDescription
data-input-soft-limitStringRequired - the input/textarea's character limit
data-soft-limit-counterStringThe selector string for the element where the input/textareas remaining character count should be shown. Make sure this is unique for each input/textarea.

Settings

PropertyTypeDescriptionDefault Value
inputsSelectorStringThe selector string that the module should use to select inputs and/or textareas.'.input-soft-limit'
parentDOM ElementThe element inside which the module will look for elements matching the inputsSelector.document
submitButtonStringThe selector string that the module should use to select the submit button. Omit this property if you do not want to use this feature.null
inputValidClassStringThe CSS class that will be applied to inputs and textareas that have exceeded their character limit.'is-invalid'

Demo

https://codesandbox.io/s/input-soft-limit-demo-wzfbq

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago