ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

SCRIPTING: limit EditText to numbers?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Barend Onneweer
SCRIPTING: limit EditText to numbers?
on Jun 19, 2012 at 12:12:49 pm

So... is it possible to limit the input type of an EditText element to numbers? Integers to be precise?

Barend

Raamw3rk - independent colourist and visual effects artist


Return to posts index

Dan Ebberts
Re: SCRIPTING: limit EditText to numbers?
on Jun 19, 2012 at 1:35:47 pm

I 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



Return to posts index

Barend Onneweer
Re: SCRIPTING: limit EditText to numbers?
on Jun 19, 2012 at 1:39:37 pm

Too 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


Return to posts index


Barend Onneweer
Re: SCRIPTING: limit EditText to numbers?
on Jun 19, 2012 at 1:44:39 pm

But 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


Return to posts index

Dan Ebberts
Re: SCRIPTING: limit EditText to numbers?
on Jun 19, 2012 at 1:48:39 pm

Sounds like a workable compromise.

Dan



Return to posts index

Barend Onneweer
Re: SCRIPTING: limit EditText to numbers?
on Jun 19, 2012 at 2:05:41 pm

Hah! 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]