Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Javascript to access a field default value?

Avatar

Former Community Member
Hi,



I'm working on a 'enter' event for text fields such that if the field contents are still on their default value, it will immediate (hence the enter) clear out, but if the contents have already been changed it will let the user simply edit their changes.



For example, I'm using the caption as the To: line on a form, then the default value of the text field says "type name here". I'd like to compare the field contents to the default upon 'enter' of the field.



Got this far:



if (this.rawValue == {default}) {

this.rawValue = "";}



and it aint working. the {default} is the only thing I can find in the scripting reference that comes close. Maybe there's a way with xfa.event.reenter??



thanks.
5 Replies

Avatar

Former Community Member
OK - here's my second attempt that doesnt work. Can somebody steer me straight on my syntax?? It always passes the if statement...



if(xfa.event.reenter == 0){

this.rawValue = "";}

Avatar

Former Community Member
Why are you using the xfa.event .....if youwant to check the value of the field you shodul use fieldname.rawValue. If this code is executing on an event in th ecurrent field you can use this.rawValue.

Avatar

Former Community Member
Paul, maybe I'm misreading the docs on event.reenter, but it looked like it was a flag about whether or not the user had ever entered that field before. Which is exactly what I'm hoping to test.



I have about 100 of these fields, so am hoping to do a simple if test, with 'relative' statements. Testing against the known default value certainly would work, but I have to write the 100 custom tests, rather than copy/paste the same thing into each field...



Do you know a way to access the value stored in the Default field in the properties tab?



thanks,

-jamie

Avatar

Former Community Member
But I could tab through it and not change anything ...then your test would fail. You could create a script object for the test and pass the object you want to test to it. Then only one line of code would be required on each field. I do not think you will have any choice but to test each field.



Another solution woudl be to get a list of fields and cycle through each one ..then only about 20 lines of code would be needed but you would test all fields at once ....assuming that there is some event (like a submit) that you woudl want to use to cause the check to happen.