Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions SCRIPTING: limit EditText to numbers?

  • Dan Ebberts

    June 19, 2012 at 1:35 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

  • Barend Onneweer

    June 19, 2012 at 1:39 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

  • Barend Onneweer

    June 19, 2012 at 1:44 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

  • Dan Ebberts

    June 19, 2012 at 1:48 pm

    Sounds like a workable compromise.

    Dan

  • Barend Onneweer

    June 19, 2012 at 2:05 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy