Files
old-holivud2/app/javascript/packs/fillable_fields.js

27 lines
723 B
JavaScript
Raw Normal View History

2020-05-31 22:38:19 +02:00
import $ from 'jquery';
class FillableFields {
constructor(element) {
this.element = element
this.target = document.querySelector(element.dataset.target)
}
fill() {
const fillables = this.element.querySelectorAll("[data-fillable-field]")
fillables.forEach((fillable) => {
const selector = `input[name='${fillable.dataset.fillableField}']`
const fillableTarget = this.target.querySelector(selector)
fillableTarget.value = fillable.textContent
})
}
}
export default FillableFields
document.addEventListener("turbolinks:load", function () {
$(document).on("click", "[data-behavior=fillable-fields]", (event) => {
new FillableFields(event.currentTarget).fill()
});
})