cannery/assets/js/maintain_attrs.js

12 lines
500 B
JavaScript
Raw Permalink Normal View History

2022-01-23 00:02:08 -05:00
// maintain user adjusted attributes, like textbox length on phoenix liveview
// update. https://github.com/phoenixframework/phoenix_live_view/issues/1011
export default {
2022-03-04 23:17:53 -05:00
attrs () {
const attrs = this.el.getAttribute('data-attrs')
if (attrs) { return attrs.split(', ') } else { return [] }
2022-03-04 22:56:52 -05:00
},
2022-01-23 00:02:25 -05:00
beforeUpdate () { this.prevAttrs = this.attrs().map(name => [name, this.el.getAttribute(name)]) },
updated () { this.prevAttrs.forEach(([name, val]) => this.el.setAttribute(name, val)) }
2022-01-23 00:02:08 -05:00
}