Skip to content

Instantly share code, notes, and snippets.

@psergi
psergi / currency_controller.js
Created March 30, 2020 23:14
Stimulus controller to handle dollar based user input when the backend is expecting cents
import { Controller } from 'stimulus';
export default class extends Controller {
onInput = (e) => this.updateHiddenInput(e.target.value);
connect() {
this.element.addEventListener('input', this.onInput);
this.initializeHiddenInput();
this.initializeInput();
}