Initial commit
This commit is contained in:
26
app/javascript/packs/fillable_fields.js
Normal file
26
app/javascript/packs/fillable_fields.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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()
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user