Created
April 11, 2022 03:49
-
-
Save thiagomajesk/f3c77e6dfbbc27ed7ba9613d41271222 to your computer and use it in GitHub Desktop.
LiveView Tips and Tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Resets a input to a value when a form is updated by LiveView. | |
* Add phx-hook="FormReset" to the form and phx-reset="" to the input you want to reset. | |
* The attribute phx-reset must contain the value that the input value will be reseted to. | |
*/ | |
Hooks.FormReset = { | |
updated() { | |
let input = this.el.querySelector('[phx-reset]:not(.invalid-feedback)') | |
let value = input.getAttribute('phx-reset') | |
input.value = value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment