1

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 ? :)

0

1 Answer 1

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 }"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.