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

234
Views
How to set min/max values for a variable in Alpine.JS

I have the following code in a web page:

<div class="cc-input-cont" x-data="{ count: 0 }">
<input type="number" name="passengers" id="passengers" class="w-full" required min="1" max="12" :value="count">
<input type="button" value="+" class="button-plus p-5" data-field="quantity" x-on:click="count++">

Clicking on the button increments the value of the input by one each time using Alpine.js inbuilt functions. This works as I want.

What I can't work out is how to make it respect the maximum value (12). Clicking the button just keeps incrementing the number past the maximum allowed value.

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

0

I managed it with the following:

<div class="cc-input-cont" x-data="{ pax: 4 }">
<input type="button" value="-" class="button-minus p-5" data-field="quantity"x-on:click="pax--;if(pax < 1){pax = 1;}">
<input type="number" name="passengers" id="passengers" class="w-full" required min="1" max="12" :value="pax">
<input type="button" value="+" class="button-plus p-5" data-field="quantity" x-on:click="pax++;if(pax > 12){pax = 12;}">
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!