Number of Inputs and RangeUpdate Value in Knockoutjs

I am working on a project, I need to enter the number, and the slider for the script is here http://jsfiddle.net/Dt7Ka/116/

<h2>Slider Demo</h2> RAM: <input type="number" data-bind="value: ram, valueUpdate: 'afterkeydown', attr: {max: 8192, min: 512, step: 1}" /> <div style="margin: 10px" data-bind="slider: ram, sliderOptions: {min: 512, max: 8192, range: 'min', step: 1}"></div> 

In the case when someone wants to enter the number manually (say, 2048), I found that the knockout overflows and does not allow me to enter 2048 correctly.

Suggestions?

+4
source share
1 answer

This is because you have set valueUpdate: 'afterkeydown' . This makes the binding try to update every time the key is pressed, and since you have minus 512 , trying to enter a value of 2 will fail.

You cannot enter 2048 because it is trying to update after the first key. If you just take this part of the binding, it will work fine.

 <input type="number" data-bind="value: ram, attr: {max: 8192, min: 512, step: 1}" /> 

http://jsfiddle.net/Dt7Ka/118/

+7
source

Source: https://habr.com/ru/post/1493260/


All Articles