Hello guys, I’m wondering if Liveview is actually capable of modifying attributes of HTML elements, for example disabling an input or a button. Something like the Document
interface that javascript has… how similar/different are the manipulations between these 2.
leex
templates are pretty dumb in the sense that they are just treated as text, rather than anything HTML specific. You can therefore modify any HTML attributes. An example of disabling a button:
in leex:
<button class="btn" phx-click="do_stuff" <%= do_button_enabled(@some_assign) %>>Do Thing</button>
in liveview code (you could also inline this in the template):
defp do_button_enabled(thing), do: if thing, do: "disabled"
Surface - http://surface-demo.msaraiva.io/documentation - has additional syntactic sugar to make this easier, and does understand HTML & attributes.
2 Likes
Makes a lot of sense to me. I was wondering if any interface was available but this can definitely do the job. Thanks @mindok!