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.

Shouldn't this script change the color of a field ?

Avatar

Level 2
if( this.rawValue == "1") { this.border.fill.color.value == "255,0,0"; }
10 Replies

Avatar

Level 2
This is the way it shows up in <View> <XML code><br /><br /><script contentType="application/x-javascript">(this.rawValue =="1"{ this.border.fill.color.value == "255,0,0";})<br /></script><br /><br />It doesn't do anything as originally displayed or as displayed here.

Avatar

Level 2
perhaps - I 'm missing something ..<br />I have the following.<br /><br /><field><br /><format><br /><\script><br /> if(this.rawValue =="1"){ this.fillColor.value == "255,0,0";}) <\/script><br /></format><br /></field><br /><br />When the field is set to 1 by the user or by any other means - <br />won't the <format> directive ensure that the script is executed ????

Avatar

Former Community Member
smde,



I am not sure what you are trying to accomplish but I would discourage directly modifying the XML source.



Typically a fill colour change is performed in response to an event such as a failed validation. In this case you would put your script in the validation event for the applicable object.



Additionally, your script is not going to work because you are checking equality "==" rather than doing an assignment "=".



this.border.fill.color.value = "225,0,0,";



will change the fill colour to red.



Steve

Avatar

Level 2
Typo in the previous post - should read as :



if(this.rawValue == "1") {this.border.fillColor.value = "255,0,0"};



I have this in the *initialize event ...

and in the

*change event



and there is no color change in the field - as if nothing was happening.

Avatar

Level 2
I must really be missing what is going on here .



I can't even get it to change color when I set the validate event check for the value of 1....

The field is a numeric field and I enter one - and the validate event has the simple if statement and ... no color change ....

Is there a cahnce that something is overriding the script logic altogether - is there a security setting or a preference condition that might explain this ????

Avatar

Former Community Member
Why are you doing it on the initialize event. The data has not been set yet. Put it on the exit event first to make sure it works. Once you validate that it works put it on the FormReady event - data has been merged by then.

Avatar

Former Community Member
Verify that your form is set up to be a Dynamic form. I find that many times, if you forget to change FROM a Static form, certain scripts work and certain ones don't. Also, try what Paul said. You may also want to try removing the quotes from your "1" in the "if" statement.



Hope this helps.



Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com

Avatar

Level 2
The script is being run - it just isnt changing anything .....

I intentionally pranged the script so that it would error out when it executed.

I set the javascipt debugger to run on erros and I got this message whne I modified the field -



missing ) after condition

1:XFA:Provider[0]:#subform[0]:Disclosure[25]:DisclosureAnswerFlag[0]:change



so changing it back to the original syntax ... the script is running - but is having no effect ... hmmmmm

Avatar

Level 2
ok - so i blew it - the line this.border.fillcolor - is meaningless -

I admit it !

I chaged the line to read :::: this.fillcolor = "255,0,0"

and it works -



Thnaks for the help