jQuery-Knob icon indicating copy to clipboard operation
jQuery-Knob copied to clipboard

Value changed although readOnly is true

Open githubjeka opened this issue 9 years ago • 7 comments

 <input value="0.648" class="dial1" data-readOnly="true">
$(".dial1").knob();

image

Clicked by input image

Clicked in any place and get 1 image

P.S. chrome browser

githubjeka avatar Apr 02 '15 06:04 githubjeka

Try data-readonly, no capital O. In the code it is looking for the data attr "readyonly". I just tested it and it worked for me. @githubjeka

gvinson avatar Apr 06 '15 17:04 gvinson

In https://github.com/aterrien/jQuery-Knob#options described readOnly. Ok when I tried readonly: true then input hasn't readyonly and value can be changed.

<div style="display: inline; height: 110.88px; width: 110.88px;">
<canvas width="110" height="110.88"></canvas>
<input value="0.05" class="knob" data-fgcolor="#f39c12" style="width: 59px; height: 36px; position: absolute; vertical-align: middle; margin-top: 36px; margin-left: -85px; border: 0px; font-weight: bold; font-style: normal; font-variant: normal; font-stretch: normal; font-size: 18px; line-height: normal; font-family: Arial; text-align: center; color: rgb(243, 156, 18); padding: 0px; -webkit-appearance: none; background: none;">
</div>

when '$(".knob").knob({max:' . $maxLoad . ', readOnly: true, width:"77%", thickness: 0.1,});'

<div style="display: inline; height: 110.88px; width: 110.88px;">
<canvas width="110" height="110.88"></canvas>
<input value="0.05" class="knob" data-fgcolor="#f39c12" readonly="readonly" style="width: 59px; height: 36px; position: absolute; vertical-align: middle; margin-top: 36px; margin-left: -85px; border: 0px; font-weight: bold; font-style: normal; font-variant: normal; font-stretch: normal; font-size: 18px; line-height: normal; font-family: Arial; text-align: center; color: rgb(243, 156, 18); padding: 0px; -webkit-appearance: none; background: none;">
</div>

But when clicked as described above then readonly doesn't work for float of value.

githubjeka avatar Apr 07 '15 05:04 githubjeka

I encontered the same problem too, the existing version seems not to support floating number. So I use a number which is [0,1000] to represent a floating number (n * 1000), and at the fortmat hook function, format it like value*0.001. Also , you may need to override the the parse hookmethod: parse:function(v): to parse the floating value back to the value repenting from [0,1000], here is a SO link: http://stackoverflow.com/questions/30881466/wrong-value-passed-to-format-hook-function-after-set-value-jquery-knob

Jaskey avatar Jul 27 '15 03:07 Jaskey

I debug the library, and the problem is that trigger a 'blur' event when you click several times

ghernandezr avatar Oct 05 '15 13:10 ghernandezr

i change the code in line 175 -176 and add if (ev.type == "blur" && $(this).prop("readonly")) return; :

...
this.$.bind(
                'change blur',
                    function(ev) {
                        if (ev.type == "blur" && $(this).prop("readonly")) return;
                        s.val(s._validate(s.o.parse(s.$.val())));
                        var v = s._validate(s.o.parse(s.$.val()));
                        if (s.cH && s.cH(v) === false) return;
                        s.val(v);

                    }
                );
...

and this solve the problem for me, meybe something like this is needed in the other blur event, i dont test that

ghernandezr avatar Oct 05 '15 14:10 ghernandezr

I ran into this problem and you solution worked great. thanks @ghernandezr

madebysquares avatar Oct 13 '15 21:10 madebysquares

Had the same problem. Solved including the attribute disabled="disabled" in the input tag, it avoided the calling of any knob event.

andrehschmid avatar Oct 18 '16 20:10 andrehschmid