An open API service indexing awesome lists of open source software.

https://github.com/markmead/alpinejs-character-count

Track the character count of an input with the option to compare against the max length 🔟
https://github.com/markmead/alpinejs-character-count

alpine-js alpinejs alpinejs-plugin javascript

Last synced: about 1 year ago
JSON representation

Track the character count of an input with the option to compare against the max length 🔟

Awesome Lists containing this project

README

          

# Alpine JS Character Count

Track the character count of an input with the option to compare against the max
length 🔟

## Example

```html


You have written characters.

You have characters remaining.



```

This will return the following:

```html

You have written 5 characters.

You have 45 characters remaining


```

The modifier in the example `50` is the max character count which you can pair
up with the `maxlength` attribute on the HTML input. If you want a more dynamic
approach to this, you can do the following.

### Using Alpine JS Refs

```html


You have written characters.

You have characters remaining.



```

Instead of passing the max character count as the modifier, you pass the name of
an Alpine JS `x-ref`.

## Install

### CDN

```html

```

### NPM/Yarn

```shell
npm i -D alpinejs-character-count

yarn add -D alpinejs-character-count
```

Then you can register the plugin.

```js
import Alpine from 'alpinejs'
import count from 'alpinejs-character-count'

Alpine.plugin(count)

window.Alpine = Alpine

Alpine.start()
```

### Stats

![](https://img.shields.io/bundlephobia/min/alpinejs-character-count)
![](https://img.shields.io/npm/v/alpinejs-character-count)
![](https://img.shields.io/npm/dt/alpinejs-character-count)
![](https://img.shields.io/github/license/markmead/alpinejs-character-count)