These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

If Else Fill Color code

Queue
Registered: Apr 27 2009
Posts: 22
Answered

Hi folks,

Alright, after banging around for a bit, here's what I've got -- an ugly nested if-else structure that's trying to change the color value of a text field based on what's entered. If there's nothing entered or it's a null value, it should reset the field back to blank. It's currently not working, of course:

form1.Page1.ProjectStatus.ProStatusGroup.txtRating1::change - (JavaScript, client)
 
if (ProjectStatus.ProStatusGroup.txtRating1.rawValue == "G") {
	this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,0"; // Green
}
else {
if (ProjectStatus.ProStatusGroup.txtRating1.rawValue == "Y") {
	this.resolveNode("ui.#textEdit").border.fill.color.value = "255,255,0"; // Yellow
}
else {
if (ProjectStatus.ProStatusGroup.txtRating1.rawValue == "R") {	
	this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,0"; // Red
}
else {
if (ProjectStatus.ProStatusGroup.txtRating1.rawValue == "P") {
	this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,255"; // Purple
}
else {
if (ProjectStatus.ProStatusGroup.txtRating1.rawValue == "B") {
	this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,255"; // Blue
}
else {
if ((ProjectStatus.ProStatusGroup.txtRating1.rawValue == null) || (ProjectStatus.ProStatusGroup.txtRating1.rawValue == "")) {
	this.resolveNode("ui.#textEdit").border.fill.color.remerge;
}
	}
		}
			}
				}
					}

No error message on the JavaScript Console in Acrobat at this time. This is a Designer form, created in Adobe Designer ES.

Thanks in advance for any corrections or advice. :)

My Product Information:
LiveCycle Designer, Windows
jonom
Registered: Jan 31 2008
Posts: 133
If you could post a copy of your form it would be easier to check out the code. ;) Acrobat.com works well.

For a big nested if...else like that I think it would be better to use a switch() statement.

switch(fieldName.rawValue) {case "G":code goes here;break;case "Y":code goes here;break;//etc. - then can also have a default setting://default://code goes here;}
jonom
Registered: Jan 31 2008
Posts: 133
Queue wrote:
if ((ProjectStatus.ProStatusGroup.txtRating1.rawValue == null) || (ProjectStatus.ProStatusGroup.txtRating1.rawValue == "")) {this.resolveNode("ui.#textEdit").border.fill.color.remerge;
One thing I just noticed is the last line above, with border.fill.color.remerge - remerge isn't valid there, you would call it separately - xfa.form.remerge(); But I don't think you need it.

I think you've also got too many closing braces at the end of the script. I think you should only need one.

Try using the Check Script Syntax button in the Script Editor (the icon of the book with the check mark).
Queue
Registered: Apr 27 2009
Posts: 22
Alright, Conditional Formatting Sample.pdf uploaded at Acrobat.com and set to "Open Access". URL here:

https://share.acrobat.com/adc/document.do?docid=331bbf3e-98ac-470f-bc73-04aee0409285

I may have had too many closing braces at the end; I did run the Check Script Syntax and did have to cull an extra one. However I did rework the code with the Switch statement as you recommended:

switch(form1.Page1.ProjectStatus.txtRating1.rawValue){case "G":this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,0"; // Greenbreak; case "Y":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,255,0"; // Yellowbreak; case "R":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,0"; // Redbreak; case "P":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,255"; // Purplebreak; case "B":this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,255"; // Bluebreak; default: this.resolveNode("ui.#textEdit").border.fill.color.remerge;

Still don't have a heartbeat; the JavaScript Console isn't giving me any error messages, either. Kookie. :)
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You are missing a closing '}' for the 'switch' statement. Also, I would make sure the 'taxRating1.rawValue' would not be case sensitive.

switch( Upper(form1.Page1.ProjectStatus.txtRating1.rawValue) ){case "G":this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,0"; // Greenbreak; case "Y":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,255,0"; // Yellowbreak; case "R":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,0"; // Redbreak; case "P":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,255"; // Purplebreak; case "B":this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,255"; // Bluebreak; default: this.resolveNode("ui.#textEdit").border.fill.color.remerge;break;} // end switch // additional code for all cases follows as needed

George Kaiser

Queue
Registered: Apr 27 2009
Posts: 22
gkaiseril wrote:
You are missing a closing '}' for the 'switch' statement. Also, I would make sure the 'taxRating1.rawValue' would not be case sensitive.
I missed it in my copy & paste but I did have the closing bracket in my code.I did notice that I forgot to put the Group name into the location of the Switch statement; I updated it, tried it (still doesn't work), and [url=https://share.acrobat.com/adc/document.do?docid=99c6dbdf-55a6-4c97-a11f-9be7f2874459]re-uploaded the PDF to Acrobat.com here[/url].

Here's the updated code that's still not working:

form1.Page1.ProjectStatus.ProStatusGroup.txtRating1::change - (JavaScript, client) switch(form1.Page1.ProjectStatus.ProStatusGroup.txtRating1.rawValue){case "G":this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,0"; // Greenbreak; case "Y":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,255,0"; // Yellowbreak; case "R":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,0"; // Redbreak; case "P":this.resolveNode("ui.#textEdit").border.fill.color.value = "255,0,255"; // Purplebreak; case "B":this.resolveNode("ui.#textEdit").border.fill.color.value = "0,255,255"; // Bluebreak; default: this.resolveNode("ui.#textEdit").border.fill.color.remerge;}

Is it possible that I'm mis-using the "this" command? Should I have the field name or the full address to the txtRating1 field there instead? There's no errors coming through the JavaScript Console...
jonom
Registered: Jan 31 2008
Posts: 133
Queue wrote:
Is it possible that I'm mis-using the "this" command? Should I have the field name or the full address to the txtRating1 field there instead? There's no errors coming through the JavaScript Console...
Been out of town the last few days, sorry I couldn't get back to you sooner.

You didn't need the full path of the field because it was operating on itself so "this.rawValue" works fine.

There was something going on with the resolveNode("ui.#textEdit") - haven't had time to look into that so I got rid of it. ;) The code now fills the box with colour - not sure if that was what you were after or not.

I also commented out the "default" line because I don't think that code was doing anything.

And I put the script on the Exit event, as the Change event was screwing things up.

switch(this.rawValue){case "G":this.border.fill.color.value = "0,255,0"; // Greenbreak; case "Y":this.border.fill.color.value = "255,255,0"; // Yellowbreak; case "R":this.border.fill.color.value = "255,0,0"; // Redbreak; case "P":this.border.fill.color.value = "255,0,255"; // Purplebreak; case "B":this.border.fill.color.value = "0,255,255"; // Bluebreak; //default: this.resolveNode("ui.#textEdit").border.fill.color.remerge;}
Queue
Registered: Apr 27 2009
Posts: 22
That's it!! :D

Thanks Jonom, got it working -- I'll work on tweaking it as I need but honestly, this is plenty good.

Also, thanks everyone else for their help. ;)