I gladly use LiveView.JS utility commands and phx-bindings. Sometimes, however, I can’t quite find what I’m looking for.
Alongside LiveView.JS’s set_attribute() and remove_attribute(), a toggle_attribute() can be useful. To easily toggle disable on an input field, for example. Say you want to disable an input field when another input field was given a value by the user. And you want to enable the input field again, when the user removes the value of that other input field. A solution could be triggering toggle_attribute() with a phx-binding that fires when an input field changes from having a value (e.g. “Example”) to not having a value (e.g. “”). Maybe phx-has-value?
JavaScript is, of course, always an option, but I enjoy the times I can use LiveView.JS.






















