Reputation: 83
I am working on a minigolf app for Android, and I am using knockout foreach bindings to display 18 rows of input number fields where users can insert there numbers of hits they needed for each hole.
My first requirement is that I want those input fields to behave so that when the user enters "9", it should automatically change to 10 (because the rules for the minigolf say that if the user uses more than 8 hits, the hole should be counted as 10).
My second requirement is that it's possible to type in numbers higher than 10 at the moment. I have to specify that you can't type in numbers higher than 10 into the input fields.
Anyone who got any idea to solve my requirements?
This is my ko foreach:
<!-- ko foreach: rounds -->
<input class="input-block-level"
name="number"
type="number"
value=""
data-bind="value: hits,valueUpdate: 'keyup'"
maxlength="2"
min="1"
max="10"/>
<!-- /ko -->
Upvotes: 0
Views: 63
Reputation: 83
I got it to work by using javascript to check up on fields both for the number 9 and number greater than 10, both will turn into number 10, so now the app works as it should
Upvotes: 1
Reputation: 1198
You could subscribe to your hits
observable to check the value to decide whether you trigger further actions or not. Check out the official documentation about subscribers.
Upvotes: 0