Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Is there any key press\\type\\hit event in textfield control.

Avatar

Level 7

Hi,

I am trying to count the number of characters typed in textfield control.

I dont find any event where it should trigger and get me counts when i type in textfield.

I am able to count the entered characters using EXIT event. But it gives me count only when i exit the control or click here and there. While typing into the textfield control its not working.

Please suggest me how do i count number of characters when i type into the textfield control.

Regards

Sunil

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

If you use the xfa.event.newText it will return the text that is in the field. So if you use that code on the change event and you type in th estring Test you will get

T, then Te, Then Tes, then Test

If you use xfa.event.change it will give you the single char that was typed. So same example as above you will get

T, then e, then s, then t

Hope that helps

Paul

View solution in original post

12 Replies

Avatar

Correct answer by
Former Community Member

If you use the xfa.event.newText it will return the text that is in the field. So if you use that code on the change event and you type in th estring Test you will get

T, then Te, Then Tes, then Test

If you use xfa.event.change it will give you the single char that was typed. So same example as above you will get

T, then e, then s, then t

Hope that helps

Paul

Avatar

Level 4

I kind of understand the idea ofwhat is supposed to happen with the xfa.event.newText script, however, I'm not really sure how I see the actual count down of characters on the form.  Can you please provide some insight into that?

Thanks!

Avatar

Level 7

Hi,

Using (in this example) formCalc, in the change event of the text field being counted:

     displayCountdownNumField = 500 - Len(xfa.event.newText)

In this case, it is 500 maximum and you'll need the SOM for displayCountdownField

Cheers,

Stephen

Avatar

Level 4

I think I'm going to need a little more help.  I'm not totally sure what you're referring to (or at least how to find) the SOM field you were describing.  I put the script in on the text field and I tried it on a numeric field and it didn't work.  I kept getting error messages that it couldn't displayCountdownNumField.  I've attached the portion of the form where I want to use this.

Thanks so much for your help!

https://acrobat.com/#d=NlzDFGAvBWvLo*jTTzLwCA

Avatar

Level 7

SOM (in this case) simply means the name of your field. Your field is named "shortitle". Change the script to:

shortitle = 35 - Len(xfa.event.newText)

Good luck!

Stephen

Avatar

Level 4

Ok, I altered the script in the text field, but then Livecycle wanted to make it a read-only field to not mess up the calculation.  I tried putting it on the numeric field but that didn't seem to do anything either.  I'm apparently really missing something.  I need to be able to type in the text field and see the countdown somewhere else.  Thanks!

Avatar

Level 4

I've come across a related question.  Is there any way to set a field for a character minimum and then do a countup of characters?  Thanks!

Avatar

Level 7

I have tested the script in your form which I downloaded and it works. What you are describing generally happens when you use the "Calculate" event.


To be clear, place the script on the CHANGE event of the field the user is typing into. The number of characters left automatically displays in the "shortitle" field (that's the name you gave it--make changes to the script if you renamed the display field).


The script is FormCalc and it works regardless of whether your "shortitle" field is a text field or a numeric field.


Don't make it complicated--it's easy--a single line of script in the CHANGE event of the field the user is typing into. That's all that is needed:


     shortitle = 35 - Len(xfa.event.newText)


Look for and Remove all other scripts you may have tried.


Cheers!


Stephen

Avatar

Level 4

That was really, really helpful.  I got it mostly working now and even set up another one in which it counts characters up from 0.  One thing though, it gives me the total count when I am initially entering text in the field, but once I leave it goes to 0 and stays there even if I go back into the text field.  How do I get it to keep that count?  I'm guessing it has to do with a different script action, but I'm ont totally sure which one.

Thanks again!

Avatar

Level 7

It is the same script--just modified. Remove the  35 -

Now it counts up, instead of down.

     shortitle = 35 - Len(xfa.event.newText)

Modified:

     shortitle =  Len(xfa.event.newText)

Avatar

Level 4

Thanks.  I got that part of it, but now my issue is that when I leave the field, no matter what number is in the numeric field it goes to 0.  How do I keep the number it ended on appearing there?

Avatar

Level 6

kingphysh ...Perfect solution! Thanks for those helpful scripts.

For anyone interested in taking it a step further to include text (i.e. You have XXX charcters remaining), here's the FormCalc script:

var count = 500 - Len(xfa.event.newText)

wordcount = Concat ("There are ", count," characters remaining.")

wordcount is the field that will display this counter text.

Place the script above in a different field which the user types into (on Change event).

I hope this helps someone like it did for me!

S

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----