Closed charliesneath closed 1 month ago
Hi, thanks for reaching out,
When there’s a validation error, we have to add an error message and update some attributes on the input
, we can easily make both of these changes at once by replacing the parent div
.
The @change
listener on the div
works because the change
event bubbles up the DOM tree once it is triggered on the input
. We could have also attached the listener to the input
directly, but personally I think it’s easier to read & maintain when all the Alpine attributes are organized together on one element, instead of spread across two.
I'm gonna close this out but feel free to reopen if you have further questions/comments.
Yes, thank you for the details here!
A simple question regarding this example for using
$ajax
:Why is the
@change
event and associateddata
attribute attached at the containingdiv
level, vs. theinput
field level?As I understand, the
onchange
event is intended forinput
, notdiv
.