9 Replies Latest reply: Jul 14, 2009 10:49 AM by Jono Moore RSS

    Change font color by javascript on exit

    Graham Calhoun Community Member

      I would like to change the font color of textfieldB when the user exits textfieldA by means of JS

       

      Right now, I am using textfieldB.fontColor = "0,0,0"; (the font color is originally (255,0,0)

       

      When I preview the form, nothing happens. No error in the console, no changing colors.

       

      What am I doing wrong?

       

      Graham

        • 1. Re: Change font color by javascript on exit
          BR001 Community Member

          Hi Graham,

           

          Seems to work for me, I've attached a sample, hope that helps.

           

          Bruce

          • 2. Re: Change font color by javascript on exit
            Graham Calhoun Community Member

            Hmmm, curious....

             

            Yes, BR, yours does work. So I altered your example to more closely fit my needs and it appears something I left out is causing the problem. See the attached example.

             

            To explain more robustly, I am filling a text box with the contents of user input from a text field. As long as I keep the second text field, it works, but although I can copy the contents of the text field to a text box, the fontColor doesn't work.

            • 3. Re: Change font color by javascript on exit
              pguerett techies

              The issue is that the field you are trying to set is not a TextField but a regular Text object. The fontColor is not a valid property of that object. To get at the Text objects font color use this expression:

               

              PlainText.font.fill.color.value

              = "0,0,0";

               

              Paul

              • 4. Re: Change font color by javascript on exit
                Graham Calhoun Community Member

                Thanks Paul, that did the trick.

                 

                I notice that there is no mention of this in the LiveCycle Designer ES Scripting Reference document. Is this because it's not a standard call, or is it because I should figure that fill.color.value can be applied to many things and not just the few mentioned in the reference?

                 

                Anyway, thanks!

                 

                Graham Calhoun

                • 5. Re: Change font color by javascript on exit
                  pguerett techies

                  Actually what I do is look at the XML source to see what path is being used to set the value ...then I merely duplicate it in the call. In the docs each property and method is defined ...you just need to know that color is a subset of fill etc.

                   

                  The fillcolor is a shortcut that was added to a TextField to make it easier than having to go through the whole path.

                   

                  Paul

                  • 6. Re: Change font color by javascript on exit
                    Graham Calhoun Community Member

                    When you said: "Actually what I do is look at the XML source to see what path is being used to set the value..." I thought, Voila! That's how I can quickly get path information to add to scripts (I'm a REAL newbie).

                     

                    Having not looked at the XML Source tab much before, I quickly went to check it out. Unfortunately, I see nothing related to hierarchy in the XML source. Are we looking at the same thing?

                     

                    Graham

                    • 7. Re: Change font color by javascript on exit
                      pguerett techies

                      Yes we are ....once in the XML source you can click on an object in the hierarchy and the cursor will move to that definition. In the case of your Text object here is the XML that defines it:

                       

                      <

                      draw name="PlainText" y="92.075mm" x="41.275mm" w="29.2864mm" h="5.2331mm">

                           <

                      ui>

                                <

                      textEdit/>

                           </

                      ui>

                           <

                      value>

                                <

                      text>Text</text>

                           </

                      value>

                           <

                      font typeface="Myriad Pro" baselineShift="0pt">

                                <

                      fill>

                                     <

                      color value="255,0,0"/>

                                </

                      fill>

                           </

                      font>

                           <

                      margin topInset="0.5mm" bottomInset="0.5mm" leftInset="0.5mm" rightInset="0.5mm"/>

                           <

                      para spaceAbove="0pt" spaceBelow="0pt" textIndent="0pt" marginLeft="0pt" marginRight="0pt"/>

                      </

                      draw>

                      Note that the name attribute of the draw is "PlainText". Then below that we have a font definition ....so following the hierarchy of the XML we get:

                       

                      PlainText.font.fill.color.value

                       

                      In some case the value attribute is implied and in others it is stated in the structure. If I wanted to get at the text that is being displayed I would use:

                       

                      PlainText.value.text.value

                       

                      Make sense?

                       

                      Paul

                      • 8. Re: Change font color by javascript on exit
                        Graham Calhoun Community Member

                        Ahhh, yes! I DO see! Thanks a bunch!

                         

                        Graham

                        • 9. Re: Change font color by javascript on exit
                          Jono Moore Community Member

                          Great tip - thanks Paul!

                           

                          Makes understanding what's going on much easier.