Expand my Community achievements bar.

Button caption changes not saved on exit

Avatar

Former Community Member
I created buttons who's captions toggle from a red 'NO' to a black 'YES' when clicked. However, when this dynamic, fillable form is saved in Acrobat Reader or Pro, the button caption changes are lost, and reset to the default. All other fields are saved as entered by the user, except for these.



Can anyone help? This has me stumped! Or is there a better way to accomplish what these buttons are doing?



Below is the javascript, activated on a click, that changes the button's caption text & color:



form1.MainSubform.TablesSubform.Table1Subform.Table1.Row1.Button6::click - (JavaScript, client)

if (Button6.caption.value.text.value == 'NO') {

xfa.resolveNode("form1.#subform[0].TablesSubform.Table1Subform.Table1.Row1.Button6.caption.value.#text").value = "YES";

xfa.resolveNode("form1.#subform[0].TablesSubform.Table1Subform.Table1.Row1.Button6.caption.font.fill.#color").value = "0,0,0";

}

else if (Button6.caption.value.text.value == "YES") {

xfa.resolveNode("form1.#subform[0].TablesSubform.Table1Subform.Table1.Row1.Button6.caption.value.#text").value = "NO";

xfa.resolveNode("form1.#subform[0].TablesSubform.Table1Subform.Table1.Row1.Button6.caption.font.fill.#color").value = "255,0,0";

}
9 Replies

Avatar

Level 10
Hi llindow,



I have had difficulty in scripting for buttons: here are two approaches that we use.



The first involves creating two buttons the same size and aligned one over the other (probably not good from a design/performance point of view). The yes_button is set to visible and the no_button is set to hidden in the Object / Field tab.



In the click event of the Yes button you would have the following Javascript:



this.presence = "hidden";

no_button.presence = "visible";

//now the rest of the script that you want this button to do



In the click event of the No button you would have the following Javascript:



this.presence = "hidden";

yes_button.presence = "visible";

//now the rest of the script that you want this button to do



Where I have scripted the appearance of a single button, I use an invisible numeric field (button_state) to track the current state of the button. The button_state field should have a default value of 0 (zero):



Then in the click event of the button you would have the following Javascript:



if (button_state.rawValue == 0) {

BUTTON6.resolveNode("caption.value.#text").value = "No"; // Change the button's caption.

BUTTON6.caption.font.fill.color.value = "255,0,0";

BUTTON6.assist.toolTip.value = "Click here to give a negative response...";

button_state.rawValue = 1;

}

else {

BUTTON6.resolveNode("caption.value.#text").value = "Yes"; // Change the button's caption.

BUTTON6.caption.font.fill.color.value = "0,0,0";

BUTTON6.assist.toolTip.value = "Click here to give a positive response...";

button_state.rawValue = 0;

}



In the button Object tab set the initial caption to "Yes" and the tooltip to "Click here to give a positive response...".



Because your button is in a table, you may need to create a column for the button_state numeric field. IF you do, then set the column width to a very small value, so that it does not appear at runtime.



Hope that helps, regards,



Niall

Avatar

Level 10
...One reason the your script may not have worked is the single quotation marks on the first line of script: 'NO', instead of double quotation marks...

Avatar

Former Community Member
Niall,

Thank you for your suggestions! I'm working through the examples in your first reply, and will post the results later. Changing from "" to '' however did not affect the outcome, unfortunately.

Till later,

Lisa

Avatar

Former Community Member
Niall,

After trying all the suggestions, although the caption toggles OK in each case, when the end-user form is saved and reopened, the caption is still reset to the default. (Actually I tried the "hidden" and "visible" buttons outside of the table, as I was having problems putting two objects in the same table cell.) So you've been successful in getting caption changes to stick? Maybe I'm missing a step in Acrobat Pro? Currently, I do Advanced > Extend Features in Adobe Reader, and Save As. It truly baffles me as to why all other fields save OK, except for these button captions.

Thank you for all the excellent examples you've provided thus far.

Regards,

- Lisa

Avatar

Level 10
Hi Lisa,



I presume that you are using LiveCycle Designer to develop the forms and then extend/use the forms in Acrobat.



I have put two buttons into a table cell (one directly below the other), but you are right it is not possible to overlap them.



When scripting you should use double quotation marks.



I am trying to understand your form. When you say that the button caption is re-setting to the default, do you mean that the button says "Button"? You can change the default in the Object/field tab to "Yes", or whatever else you want. You decide what the default appearance of the button (font, colour, etc.) will be, not Acrobat.



I don't think that you are doing anything wrong in Acrobat. The issue is in LiveCycle. Select the button and go to the Object Tab, in the caption box change "Button" to "Yes". Then in the Accessibility Tab add your tool tip. This should solve the problem (I hope).



Of the two possible solution I would recommend the single button, invisible numeric find (in an adjacent narrow cell) and the scripting solution, because you are putting the button into a table.



I have put a sample on share,acrobat.com: https://share.acrobat.com/adc/document.do?docid=5cfe3a71-4ad4-44bc-838d-9ec8a2014dbf



Hope that helps,



Niall

Avatar

Former Community Member
Niall,

Sorry for not being more clear. The button caption starts out as a red "NO". The problem is that even if the end-user has clicked to change the caption to a black 'YES', when the form is saved and reopened, the caption is always a red "NO". I don't know if this is pertinent, but additional rows in the table can be added by the user, and rows can be deleted too, sort of like the PurchaseOrder example.

Each row actually has four of these buttons to be toggled, with varying text. When the buttons weren't working, I even tried to just use textfields that change on a click. But this was not satisfactory as the text will not refresh until clicking outside the textfield.

Thank you for your sample code. I will go over it and see if I can get this thing to work, and then get back to you with the results. You have been very helpful, and I really appreciate your taking all this time to help me.

Thanks,

- Lisa

Avatar

Level 10
Hi Lisa,



If the button only exists to change the colour of the text (i.e. the button does not do any other action), then I think that you would be better off with a drop-down list in each of the cells. The default value of the drop-down list would be set to "NO" (in the Object/Value tab) and the font red.



Then set the values for the responses in the Object/Binding tab to YES = 1 and NO = 0.



Then have the following Javascript in the Initialise AND Exit event of each drop-down list.



if (this.rawValue == 0) {

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

this.assist.toolTip.value = "This is a negative response...";

}

if (this.rawValue == 1) {

this.font.fill.color.value = "0,128,0";

this.assist.toolTip.value = "This is a positive response...";

}



You should be able to set the four buttons in a single row and then when additional rows are added during runtime, each drop down list should operate independently.



There is no need for the button_state numeric field in this case, as all the script is within each drop-down list.



If using checkboxes to control the Yes/No appearance, you could put your code in the MouseUp event.



Good luck,



Niall

Avatar

Former Community Member
Niall,

That's a very good suggestion, using drop down lists, instead of the problematic buttons, since I'm only using the buttons to toggle red NO/black YES. Thank you for all of your help and great examples. You've been a wealth of information!

Thanks yet again,

- Lisa

Avatar

Level 10
You're welcome Lisa, goood luck with the project!



N.