admin管理员组

文章数量:1405336

I've been working on a project I need a number input and a slider see fiddle here /

<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 where someone want to manually enter a number (say 2048) I find that knockout goes into overkill and prevents me from entering 2048 correctly.

Suggestions?

I've been working on a project I need a number input and a slider see fiddle here http://jsfiddle/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 where someone want to manually enter a number (say 2048) I find that knockout goes into overkill and prevents me from entering 2048 correctly.

Suggestions?

Share Improve this question asked Jul 24, 2013 at 17:38 x20marx20mar 4895 silver badges18 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

It's because you have valueUpdate: 'afterkeydown' set. This causes the binding to try to update every time a key is pressed, and since you have a min of 512, trying to enter a value of 2 is going to fail.

You can't enter 2048 because it tries to update after the first key. If you just take our that part of the binding it will work fine.

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

http://jsfiddle/Dt7Ka/118/

本文标签: javascriptNumber inputs and ranges valueUpdate in KnockoutjsStack Overflow