memEx/assets/js/maintain_attrs.js

9 lines
436 B
JavaScript
Raw Normal View History

2022-01-22 23:59:58 -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-01-23 00:00:53 -05:00
attrs () { return this.el.getAttribute('data-attrs').split(', ') },
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-22 23:59:58 -05:00
}