Sha256: 919662ed6a582beab0986eab00cd1cba6f74a5efd88aee96913b2e95a43ef328
Contents?: true
Size: 1.08 KB
Versions: 135
Compression:
Stored size: 1.08 KB
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = [ "field" ] static values = { original: String, dirty: Boolean } connect() { this.recordOriginal() } recordOriginal() { if (!this.hasOriginalValue) { this.originalValue = this.value } this.dispatch('original-recorded', { detail: { originalValue: this.originalValue }, target: this.field }) } revert(event) { if (this.hasOriginalValue) { this.value = this.originalValue } this.dispatch('reverted') } get field() { if (this.hasFieldTarget) { return this.fieldTarget } return this.element } get value() { switch (this.field.type) { case "checkbox": return this.field.checked } return this.field.value } set value(newValue) { switch (this.field.type) { case "checkbox": this.field.checked = (newValue === "true" || newValue === true) break default: this.field.value = newValue break } } }
Version data entries
135 entries across 135 versions & 1 rubygems