Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Color a field

Avatar

Level 2

Hello,

I am new to LiveCylce and I have a question.

I own a auto repair shop and have a vehicle inspection form that I use for vehicles that come into the shop. Each item on the form has three checkboxes labeled for the condition of the item.

I am trying to make a new inspection form and each item on the inspection form would have one rectangle next to it that I would be able to change color depending on the condition of the item "Red" for severe or safety issue "Yellow" for recommended & "Green" for acceptable.

I would like to have three buttons on the form that when pressed would change the color of the rectangle that I am on for each color labeled  Severe, Recommended & Acceptable. Or one button that could be pressed once for Red twice for yellow and three times for green. I just want to have one instance of this on the form so I don't have buttons all over the place.

I have attached a pdf of the old form so you can see what it consisted of.

Thanks in advance

48 Replies

Avatar

Level 2

Naill

I tried this but do not really know how to code it maybe you could try and let me know if it works.

I added the code to the RecButtonNew.xdp fragment at the end which is what you stated I believe.

Then to try it I made a reset button on the editing page for the fragment and added the script to it and it did not work probably because I don't quite know what I am doing (go figure) car guy trying to be a programmer Ha Ha!!

Thanks Brother

John

Avatar

Level 10

Hi John,

Can you upload the form and fragment (in a zip file) to a file sharing site?

Acrobat.com or YouSendIt.com and post the published link on the forum.

Niall

Avatar

Level 10

Hi John,

Here is the form back: https://acrobat.com/#d=6pftCrGAL93DAog8tQ2oKQ

I think that your fragment for the button may be corrupted, in that I could not edit it or access it in any way.

LittleSnapper1.png

If you can edit the fragment then you could put the following script in the full event:

this.border.fill.color.value = "0,157,2";

this.caption.value.text = "A";

this.caption.font.fill.color.value = "255,255,255";

Then the reset button has the following script after the reset script, for each button:

Column1.EXTERIOR.Lights.bodyButton1.execEvent("full");

This calls the full event of bodyButton1, which will turn it green, and 'A'.

I have changed the first column back to buttons. Unless you are in a server environment I don't think that fragments make sense. If the form and fragment get separated (form used on a different computer) then the buttons may not appear.

So my suggestion, if you can edit the fragments then just add the script above, name your fragments on the form (so the reset button can reference them) and add the lines of script to the reset button for each coloured button.

If your fragments are causing any difficulty there, then I would delete and copy the button from the first column, align to the top of the dropdown, name and reference in the reset button.

Parallels Desktop.png

A bit of work either way, but the start is there for you.

Good luck,

Niall

Avatar

Level 2

Naill,

Is there a way to use a wild card in the script instead of calling each button individually in the reset button?

John

Avatar

Level 10

Hi John,

There is no magic bullet (afaik).

The trouble is that you have the buttons/fragments in different subforms, so trying it hit all of them in a single shot is not easy.

It would be possible if the buttons were in the same subform as the reset button and all of the buttons had the same name "conditionBtn". Lets say there are 14 buttons.

var vHit;

for (var i=0; i<14; i++)

{

     vHit = xfa.resolveNode("conditionBtn[" + i + "]");

     vHit.border.fill.color.value = "0,157,2";

     vHit.caption.value.text = "A";

     vHit.caption.font.fill.color.value = "255,255,255";

}

This will loop through and reset all fourteen buttons. But the way you have set up the form it is not practicable.

You could take the buttons out of the subforms, so that they are all in the root node (same as reset button) and then give the buttons the same name.

Goos luck,

Niall

Avatar

Level 10

The above script is on the basis that all of the reset is happening in the Reset Button.

If you leave the script in the full event of the individual buttons then the reset script could become.

var vHit; 

for (var i=0; i<14; i++)
{
     vHit = xfa.resolveNode("conditionBtn[" + i + "]");
     vHit.execEvent("full");
}

There is a couple of choices for you at least.

Have a good weekend - its a long one here, so back Tuesday.

Niall

Avatar

Level 2

Naill,

This stuff is Greek to me. I now understand what you were trying to tell me by examining the form that you sent me. Maybe I need to see the new code in the form to understand it better, as I was saying before "car guy turns into programmer"!*^@#$#%%

Have a great long weekend

John

Avatar

Level 10

Hi John,

Drizzling here at the moment, should clear up soon.

Here is the form back to you: https://acrobat.com/#d=BgK-QNdLWXm8AkrUdu9Qcw

You will see that I have moved all of the 14 buttons out into the root node and they all the the same name "bodyButton". LC Designer automatically adds on the instance number in square brackets, "bodyButton[3]". Note that even though the buttons are now in one subform, their position has not changed on the form.

Because they are in the same subform and have the same name, it makes it much easier to reference in a loop. So I have taken the script out of the full event of the buttons and amended the script in the click event of the reset button:

xfa.host.resetData();


// Reset all the buttons

var vHit;

for (var i=0; i<14; i++)

{

     vHit = xfa.resolveNode("bodyButton[" + i + "]");

     vHit.border.fill.color.value = "0,157,2";

     vHit.caption.value.text = "A";

     vHit.caption.font.fill.color.value = "255,255,255";

}

Because the loop runs through from 1 to 13, you can see that the xfa.resolveNode resolves the two components (1) the "bodyButton" name and (2) each of the instances, using "i". This resolved node is assigned to a variable "vHit" and this is used for each of the following resetting script lines.

I have also posted another example on our blog, which may be of help: http://assurehsc.ie/blog/index.php/2010/08/referencing-objects/

I hope that this helps you get to grips with referencing - we all have to start somewhere ;-).

Niall

Avatar

Level 2

Naill,

Works pretty good but I think the tab order got messed up somehow. The first button "bodyButton" is in the sub group for "Lights" if you try to move any other instances of "bodyButton" in the list up to make it lower in the tab order say make bodyButton(0) go from 99 in the tab order to number 9 it will just revert back to its original position, tab position 99 (will not stay at 9 in tab order).

I think it is because all other bodyButtons except "bodyButton" are not in the groups with the dropdown fields anymore. The only button that tabs correctly is the original "bodyButton" because it is in the group with the "Lights" not on its own. Is there a way to get the tab order working correctly without having to put all the buttons in the dropdown groups like they were in the last version of the form? LC really has issues with the tab or doesn't it!! Should be able to change tab order anyway you want independent of hierarchy.

Thanks in advance

John

Avatar

Level 10

Hi John,

We're back to post 12 above - tabbing  can be a right pain. Here is the form with a custom tab order running from the top QA fields through the first column (button - dropdown). https://acrobat.com/#d=VYli8K49F-g9c-03g4BYLA

Parallels Desktop2.png

I would only go the custom tabbing at the VERY last stage, as adding a new object can really throw the tabbing order out.

I think at this stage you have a choice:

  1. Work with the solution in this post, which has cleaner scripting for the reset buttons, but relies heavily on a custom tabbing order (which can break very easily).
  2. Work with Friday's solution, which will have easier tabbing order (because button and dropdown are grouped in subforms), but requires a bit more involved scripting for the reset.

Both options are good to go for resetting the buttons, but I would go for option 2, as the custom tabbing order can be troublesome.

The script for option 2 is set up for the 14 buttons (full event) and the reset button (click event). You just need to follow this for the remaining buttons.

Friday's solution (option 2) is here: https://acrobat.com/#d=6pftCrGAL93DAog8tQ2oKQ

Good luck,

Niall

Avatar

Level 2

Naill,

I will golf this morning and think about what I will think about what option to use. I am leaning more towards option 2 for the same reasons as you (tab order gets broken easily).

John

Avatar

Level 2

Naill,

Greetings! The form is getting there now. Got the coding for the button reset completed.

Made a conditional print button so That fields get filled in before the form is printed.

I have two other questions / dilemmas with the form

1. I would like the dropdowns required to be filled in if the button is not in the "A" state or "N/A" state

2. If any of the tires are not in the "A" state then size and wheel type need to be filled in too before the form will print.

Can this be done I have attached a link to the file.

Thanks in advance

John

612-701-4755

Avatar

Level 10

Hi John,

Looks good. https://acrobat.com/#d=NJjaOfR7jL6sXU4-CBt5TA

I have added script to the first button - lights. If the button state is 'A' or 'N/A' then you would use:

LightsDropdownList.mandatory = "disabled";

Any other state:

LightsDropdownList.mandatory = "error";

This turns on and off the mandatory/required state for the field associated with the button.

Note that you will have to script each button individually specifically referring to the adjacent field. There is no shortcut.

One tip: when you are in the script editor (when a button is selected), you can create a new line in the script and then hover the mouse over the associated field. When you press and hold the Control key you will notice that the cursor turns into a 'V'. When its like this click the object and LC Designer will automatically insert the correct object reference into your script.

I have also amended the print button script to check that mandatory fields are completed before it will allow the form to print. This will only work if the button is clicked.

if (xfa.form.execValidate() == true)

{

     xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

}

else

{

     xfa.host.messageBox("You must fill in the mandatory fields before you can print this document. \n\nThank you!", "Vehicle form - printing error", 0, 0);

}

Niall

Avatar

Level 2

Hello,

Long time no talk to!

I started the scripting process on all the "A" buttons / DropDown lists. I then previewed in Acrobat when the "Reset Form" button is clicked if  an "A" button is in any other state than "A" the DropDown list does not reset meaning the DropDown is still a mandatory field and is bordered in red. I don't know if something needs to changed in the script for the "A" button or the "Reset Form" button to reset everything back to its original state.

I don't want to change the script on anymore buttons until this is resolved.

Please advise me oh wise one!

John

Avatar

Level 10

Hi John,

Working off the current version I have, the reset button fires the Full event of all of the buttons.

So you can add a line settings its corresponding dropdown to not mandatory:

LightsDropdownList.mandatory = "disabled";

I have done this to the first button (Lights). https://acrobat.com/#d=x0qfeXHtoymoOhHSeq1MxA

Parallels Desktop1.png

Alternatively you could set up a function to set all dropdowns to not mandatory.

I hope that helps,

Niall

Avatar

Level 10

Hi John,

Here is revision 16: https://acrobat.com/#d=PKFCsF-q7kBrBlsm09SGrg

I have amended Paul Gurette's excellent LockAllFields function and used this to reset the fields. The function is in a script object called 'customReset'. This contains all of the script to reset the buttons and dropdowns.

The click event of the reset button calls the function five times, each time passing the name of the column subform into the function. The function then works through all of the objects in the subform and takes appropriate action.

At this stage the only thing left is to add in the script into the 'A' buttons to set the mandatory property of the dropdowns. I have done the first one in each column.

Good luck,

Niall

Avatar

Level 2

Hi Naill,

"I got blisters on me fingers" (the Beatles "Helter Skelter")

Here is revision 17 https://acrobat.com/#d=BVUp*qVijsDkn09GXYFyFA

I think I've finally got it! One last thing (I hope it's the last)

I would like the tire (or "tyre") size and type to be filled out if any of the tires are  "R", "S", "SS" so the tire size and type get noted on the inspection. I believe it can be done just am stumped on how to exactly.

Boy i sure didn't think this was going to be this hard. Had some busy fingers today and then after I coded all the buttons and saved after each one I forgot to save all the time when I started filling in the dropDowns and got the dreaded lockup!!%#^#. Found the folder 8.2 and deleted it Livecycle does not seem to crash now but had to re-fill in a bunch of dropDowns I had already filled in... damn!

Cheers

John

Avatar

Level 2

I don't know if you know this but we hve been working on and off on this for just about a year September 27th 2009!

Avatar

Level 2

Naill,

Figured out the Tire & Size issue just made those fields mandatory if any of the buttons are changed from "A" or "N/A" in all the tire buttons.

I wanted to make the caption for the tire size and type to be double lined, example

Tire

Size

Tire

Type

I tried searching for the XML version of break I tried using HTML tag </br>. but does not work in XML

John