Highlighted

Looping thru fields

Avatar

12-01-2009

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)?

Replies

Highlighted

Avatar

Avatar

foleyb77

Avatar

foleyb77

foleyb77

12-01-2009

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...?
Highlighted
Highlighted

Avatar

19-01-2009

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
Highlighted

Avatar

Avatar

Ryan_Lunka

Avatar

Ryan_Lunka

Ryan_Lunka

20-01-2009

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
Highlighted

Avatar

20-01-2009

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"

}
Highlighted

Avatar

Avatar

Ryan_Lunka

Avatar

Ryan_Lunka

Ryan_Lunka

22-01-2009

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