mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
22 lines
466 B
JavaScript
22 lines
466 B
JavaScript
import { Controller } from "stimulus";
|
|
|
|
export default class extends Controller {
|
|
static targets = ["count", "input"];
|
|
|
|
connect() {
|
|
this.inputTarget.addEventListener("keyup", this.countCharacters.bind(this));
|
|
this.countCharacters();
|
|
}
|
|
|
|
countCharacters() {
|
|
this.displayCount(
|
|
this.inputTarget.value.length,
|
|
this.inputTarget.maxLength
|
|
);
|
|
}
|
|
|
|
displayCount(count, max) {
|
|
this.countTarget.textContent = `${count}/${max}`;
|
|
}
|
|
}
|