Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top