Activity › Forums › Adobe After Effects Expressions › SCRIPTING: limit EditText to numbers?
-
SCRIPTING: limit EditText to numbers?
Posted by Barend Onneweer on June 19, 2012 at 12:12 pmSo… is it possible to limit the input type of an EditText element to numbers? Integers to be precise?
Barend
Barend Onneweer replied 13 years, 11 months ago 2 Members · 5 Replies -
5 Replies
-
Dan Ebberts
June 19, 2012 at 1:35 pmI don’t think so, unless you set up an onChanging() function (I’ve never tried it, so I don’tknow for sure) or add an event listener for keyup or keydown events to catch illegal characters as the come in.
That sounds pretty drastic though. I generally just take what the user has typed, try to convert it to an integer with parseInt(), and reject it if isNaN() comes back true.
Dan
-
Barend Onneweer
June 19, 2012 at 1:39 pmToo bad. Something like inpuType: integer would be an elegant solution. parseInt is correction after the fact whereas constraining the input on … ehm… input would be nice.
Oh well… I’ll stick with the parseInt for now… Thanks.
Raamw3rk – independent colourist and visual effects artist
-
Barend Onneweer
June 19, 2012 at 1:44 pmBut I could of course do the parseInt upon onChange of the text field to catch issues before running through the rest of the script and letting the user adjust if necessary before hitting ‘Go’.
Just thinking out loud here.
Raamw3rk – independent colourist and visual effects artist
-
Barend Onneweer
June 19, 2012 at 2:05 pmHah! That works exactly like I wanted… And with very little code… Upon onChange of the editText I did a parseInt and if NaN set the value to 0…
If I sound giddy with excitement with these small results: bear with me here… I started Lloyds FXPHD course a week and a half ago… and hadn’t ever written one line of Javascript before that. And now in the middle of my second script, fully automating my greenscreen workflow. Going a bit overboard even.
😉
Raamw3rk – independent colourist and visual effects artist
Reply to this Discussion! Login or Sign Up