0

How can I dynamically add a mask to the textbox input in google app scripts? I have a textbox that is intended to get a date, but I want the script to add the slash (/) by itself.

For example: the user enters "01022009" and dynamically the script gives the result "01/02/2009".

But not after all the numbers are added by the user. The behaviour I would like to get is that after typing "01" automatically the script add the slash after that an so on, so the final result would be "01/02/2009".

I've tried many ways but could not get the expected result.

NullUserException
  • 83,810
  • 28
  • 209
  • 234
  • 1
    Please don't do this, it's annoying as hell. Don't mess with my input *while* I'm typing, add the damn slashes after I am done if you need to. – NullUserException Oct 18 '12 at 17:51
  • hahaha, Ok you dont need to be that mad! I already implemented a workaround for that issue. Instead of dinamically formating the user input, I added three textboxes with two labels containing the slashes between them. I also added a third invisible textbox to receive and concatenate the first three textboxes inputs and the slashes and then save that information to a fusion table as one string. –  Oct 20 '12 at 13:42

1 Answers1

0

This can't be done if you're using UiApp, because clientHandlers are limited and can't do this, and serverHandlers are just to slow to effective take action while the user types.

If you use HtmlServices, it may be possible to get something acceptable working, but I'm not sure you'll be able to get it working perfectly, because AFAIK it is not possible to get the current caret position, due to Google Caja sanitization of your client-side javascript code.

Anyway, as suggested on a comment to your question, changing the input while the user types it is pretty annoying, I wouldn't do it.

Henrique G. Abreu
  • 17,406
  • 3
  • 56
  • 65
  • Henrique, thank you for your help. The ideal would be doing that with client handler, however as you said, client handlers are too limited to do that and also the server handlers are too slow. I implemented the solution I mentioned on the comment above, and now it works perfectly. –  Oct 20 '12 at 13:44