Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Modifying Event Handlers During Run Time?

Avatar

Level 2

Hi,

I'm creating an interactive document list that renders a two-column table based on the selection of a drop-down list. The columns are added using the instanceManager based on the first row that is always present (independent of the selected item of the drop-down list).

The first column contains the doc name (fixed for row 1 and pulled from an array starting with row 2), the second column contains a button that has the the following JS code for its "clicked" event (also fixed for row 1):

xfa.host.gotoURL("TrainingGuides\\Basics.pdf", 1);

What I'm trying to accomplish, is changing the "clicked" script of each row's button to point to the correct URL based on the current document's title (from the "docs" array).

I managed to change the value of each button's "event.script.value" element, but in the final PDF the URLs of all buttons are still pointing to "TrainingGuides\\Basics.pdf" instead of the changed URL. What confuses me is the fact that the correct URLs are displayed in the alert messages...

This is the relevant JS code snippet from the drop-down list's "change" event:

for (i = 1; i < docs.length; i++) {
   // Add row based on first row.
   newRow = form1.mainframe.DocsTable.Row1.instanceManager.addInstance(1);
   // Change text of left table cell to name of current doc.
   newRow.LeftCell.value.resolveNode("#text").value = docs[i];
   // Change the button script of the right table cell to point to the current doc.
   newRow.Button1.resolveNode("#event[0]").script.value = "xfa.host.gotoURL('TrainingGuides\\" + docs[i] + ".pdf', 1)";
   // Just for debugging... This displays the current script value.
   app.alert(newRow.Button1.resolveNode("#event[0]").script.value); }

I guess there is something missing that kind of "refreshes" the buttons' URLs, but all my playing around with remerge(), recalculate() and relayout() just made things worse.

Can anybody help me with this?

Marcus

2 Replies

Avatar

Former Community Member

The issue is that the script is being taken from the Template dom and you are adjusting the Form Dom. You cannot adjust the Template after rendering. Why not change the command to use a variable instead of a hardcoded value? Something like this:

xfa.host.gotoURL("TraininngGuides\\" + URLinVar , 1);

Then set the URLinVar dynamically when the user clicks the link. You can get the index of the parent object using this.parent.index to know which row they choose, then you can get the 1st column filename based on that index and set the var (all on the fly).

Make sense?

Paul

Avatar

Level 2

This makes perfect sense! And it works, thanks a lot!