Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpine.js compatibility breaks with <select> value becoming object '{value: "x"}' instead of 'x' #1222

Open
Fak3 opened this issue Oct 12, 2024 · 1 comment
Labels

Comments

@Fak3
Copy link

Fak3 commented Oct 12, 2024

When user selects <option value="x">, then <select> value bound with alpinejs x-model attribute becomes '{value: "x"}' instead of 'x'

To Reproduce

<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.1/dist/cdn.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/choices.js@11.0.2/public/assets/scripts/choices.min.js"></script>

<select 
  x-init="new Choices($el, {})" 
  x-data="{curvalue: null}" 
  x-model="curvalue" 
  @change='console.log(JSON.stringify(curvalue))'
>
    <option value="x">First item</option>
    <option value="y">Second item</option>
</select>

Expected behavior
Expected same behavior as regular <select>:
When user selects <option value="x">, then <select> value becomes 'x'

Choices version and bundle

  • Version: 11.0.2

Desktop (please complete the following information):

  • OS: openSUSE Tumbleweed
  • Browser: Firefox
  • Version 131.0
@Fak3 Fak3 added the bug label Oct 12, 2024
@Fak3 Fak3 changed the title <select> value becomes object '{value: "x"}' instead of 'x' Alpine.js compatibility breaks with <select> value becoming object '{value: "x"}' instead of 'x' Oct 12, 2024
@Fak3
Copy link
Author

Fak3 commented Oct 12, 2024

My current workaround is to assign alpine data manually on change instead of using x-model:

<select 
  x-init="$el.choices = new Choices($el, {})" 
  x-data="{curvalue: null}" 
  @change='curvalue = $el.choices.getValue(true)'
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant