add maintainattrs hook for textareas

This commit is contained in:
shibao 2021-09-12 18:55:03 -04:00 committed by oliviasculley
parent 8827858204
commit 7b79dbf935

View File

@ -17,8 +17,15 @@ import {Socket} from "phoenix"
import topbar from "topbar"
import {LiveSocket} from "phoenix_live_view"
let Hooks = {};
Hooks.MaintainAttrs = {
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)) }
};
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}})
// Show progress bar on live navigation and form submits
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})