lo-th / uil

simple javascript ui
http://lo-th.github.io/uil/
MIT License
555 stars 50 forks source link

Error when .listen() is used with 'Number' type inputs. #29

Closed modulatedthreat closed 3 years ago

modulatedthreat commented 3 years ago

when .listen() is put on a numeric input I get console errors.

uil.js:5749 Uncaught TypeError: Cannot create property '0' on number '5' at Numeric.validate (uil.js:5749) at Object.keyup (uil.js:2020) at Object.handleEvent (uil.js:1649)

Uncaught TypeError: Cannot create property '0' on number '-0.63' at Numeric.validate (uil.js:5749) at Object.clearInput (uil.js:1950) at Gui.handleEvent (uil.js:7543) at Object.handleEvent (uil.js:1687)

going to line 376 in src/proto/Numeric.js we see: this.value[i] = nx; this.value is a number, not an array. To attempt an easy fix I changed it to: this.setValue(nx); That stopped the errors, but the .listen() doesnt work, and the value does not update. To recreate the problem just open the uil_listen.js example and change one of the inputs to type: 'Number'.

My ultimate goal is to have a slider and a numeric text input keep control and sync with a variable.

lo-th commented 3 years ago

Hi well this.value should be a array problem's is on function setValue thanks to see that is fixed

modulatedthreat commented 3 years ago

Thank you!! uil.js is WAY better than dat.gui. I dont know why it doesn't get more attention.

On Thu, Sep 23, 2021 at 11:33 PM lo-th @.***> wrote:

Closed #29 https://github.com/lo-th/uil/issues/29.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lo-th/uil/issues/29#event-5353870340, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKLXUF3B77BZE66IAZD3GH3UDQESFANCNFSM5EUWLSNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

modulatedthreat commented 3 years ago

I have a question. https://github.com/williammanco/uniforms-gui uses your code to put a slider with a text number input on the same line. I cant figure out how they get your code to do that. For example, the way the variable "uRed" can be controlled in the sandbox https://codesandbox.io/s/4xn7po9l90 on the readme is exactly what I'm trying to do. Is there something already built in that does this?

lo-th commented 3 years ago

Well you can use gui with a object {} material.uniform is a object with propriety like uRed so to update material you can use ui.add( material.uniform, 'uRed ', { min:-5, max:5 } ) no need use listen because the object is link to slider so propriety uRed is update by gui

hope that help

modulatedthreat commented 3 years ago

Sorry, I wasn't very clear, and its not a big deal, but I was talking about the slider type and clicking on the number beside the slider and typing a different number in to change it.

lo-th commented 3 years ago

ha ok :) is only possible in basic slider. not include in knob or Circular