Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
alpinejs Checkbox checked on init or based on x-modal not working

When loading alpinejs it uncheckes all checkboxes, i don't know why it is doing so but it is.

<div x-data="{ colors: [orange] }">
    <input type="checkbox" value="red" x-model="colors">
    <input type="checkbox" value="orange" x-model="colors" :checked="colors.includes('orange')">
    <input type="checkbox" value="yellow" x-model="colors">
    <div class="pt-4">Colors: <span x-text="colors">orange,red,yellow</span></div>
</div>

So when loading the code above I need orange to be checked, but it doesn't. does somebody knows whats going on here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to add single quote in the array ['orange'] and you don't need the :checked...

<script src="https://unpkg.com/alpinejs@3.3.4/dist/cdn.min.js"></script>

<div x-data="{ colors: ['orange'] }">
    <input type="checkbox" value="red" x-model="colors">
    <input type="checkbox" value="orange" x-model="colors">
    <input type="checkbox" value="yellow" x-model="colors">
    <div class="pt-4">Colors: <span x-text="colors"></span></div>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!