I would like to bind custom validation my view model using knockout validation. On my form I have form with input and drop down. When value of drop down is changed I need to change range of digits in my input. For example from 0 to 10 or when other value is chosen from 50 to 100. Any ideas ? :)
1 回答
In the Knockout-Validation wiki there is a page dedicated to Custom Validation Rules.
That being said I don't think validation is what you want to solve your problem. You should be able to handle this by using Knockout's subscribe functionality.
You can explicitly subscribe to your drop down value observable and in that subscribe function you can change the range of the digits in your input. Should be pretty simple.
Here is some code that does something like what you want and it uses Knockout's subscribe functionality.
This is what your binding will look like to change the range for input type number.
data-bind="value: $data.inputVal, attr: { min: $data.inputRangeMin, max: $data.inputRangeMax }"