Created
January 28, 2023 15:09
-
-
Save ffflabs/0e9bb354d73eb4b93f7b4b129993950c to your computer and use it in GitHub Desktop.
alpinejs $watch issue
This file contains hidden or 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
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script> | |
<form x-data="form()" x-on:submit.prevent="submit"> | |
<div> | |
<label> | |
A | |
<input x-model="a" /> | |
</label> | |
</div> | |
<div> | |
<label> | |
B | |
<select x-model='b'> | |
<option>foo</option> | |
<option>bar</option> | |
</select> | |
</label> | |
</div> | |
<button>Submit</button> | |
</form> |
This file contains hidden or 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
function form() { | |
function submit() { | |
console.log(this.a); | |
} | |
return { | |
init() { | |
this.$watch('b', () => this.submit()); | |
}, | |
a: '', | |
b: 'foo', | |
submit | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment