sunmingtao / sample-code

3 stars 4 forks source link

Number.isInteger(quantity) always evaluates to false #106

Closed sunmingtao closed 4 years ago

sunmingtao commented 4 years ago
<div class="pull-left">
    <input type="number" class="form-control" placeholder="Quality" v-model="quantity">
</div>
<div class="pull-right">
    <button class="btn btn-success" @click="buyStock" :disabled="quantity <= 0 || !Number.isInteger(quantity)">Buy</button>
</div>

Number.isInteger(quantity) always evaluates to false, therefore, the button is always disabled.

sunmingtao commented 4 years ago

Turns out the variable quantity is a string. That's why it's never an integer. Fix 1: Change to !Number.isInteger(quantity * 1) Fix 2: v-model="quantity" changes to v-model.number="quantity"