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.

Looping thru fields

Avatar

Former Community Member
Hello,



I would liek to write a function that upon ready:form would check to see if some fields have some text in them and if so - make sure they are visible.



Currently I have this on ready:form:



myField = topmostSubform.Page1.StaffPrep.WhatsNew



if (myField.Prod.Prod_Note.rawValue.length==0) {

myField.Prod.Prod_Note.presence = "hidden";

myField.Prod.CheckBox1.value = "Off";

}

else {

myField.Prod.Prod_Note.presence = "visible";

myField.Prod.CheckBox1.value = "On";

}



How would I change this to check all 11 fields (which have names like HR_Note and Sales_Note and Misc_Note)?
6 Replies

Avatar

Level 2
How about create an array with all 11 field names, loop through the array to check the indivual fields.



Have you tried to accomplish this through the object validation under the value tab...?

Avatar

Former Community Member
I have not - let me give that a try.



Thanks for responding.

Avatar

Former Community Member
I have tried writing the loop but it seems to be over my head. Can anyone help me with this?



I need to loop thru 11 fields, check their length and make them visible or invisible.



Thank you

Avatar

Former Community Member
You can loop through each object in the hierarchy using things like nodes.length. Email me if you'd like a better explanation and some sample script showing how to do that.



Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com

Avatar

Former Community Member
Thanks for the offer. I will do that. In the meantime - is this on the right track?



var y = ['TextField1_note','TextField2_note','TextField3_note'];



for each (x in y) {

if (x.rawValue.length == 0) {

x.presence = "invisible"

}

else {

x.presence = "visible"

}

Avatar

Former Community Member
Also, I know that I sent you a better solution, but I noticed something revisiting this post. Using "x.rawValue.length == 0" is probably not the best way to go. If "x.rawValue" is null, "x.rawValue.length" will be undefined and so, your script will not enter the "if" statement. Use "x.rawValue == null" instead.



Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com