These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Set the event handler for a field at runtime.

ek98hkeg
Registered: Jun 8 2007
Posts: 6

Is it possible to dynamically set the (e.g.) mouseEnter event script for a field?
I.e. I want to programatically set a text field's change event to call a javascript function.

My Product Information:
Reader 7.0.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, you can do this. Use the "Field.setAction()" function. Look it up in the Acrobat JavaScript Reference.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ek98hkeg
Registered: Jun 8 2007
Posts: 6
Sorry, I was not clear enough. I'm using a LiveCycle Designer form. The "Field.setAction()" is listed as not supported in designer forms.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Sorry I didn't answer this earlier, we don't get notices for the follow up questions so I never know what's happening

I havn't tried this with LiveCycle forms, but I think that "rblaa" (the guy who wrote the comments below) has the right idea. I'd try changing the event script in the Template model (xfa.template), then save and re-open the form.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

rblaa
Registered: Jun 15 2007
Posts: 3
I am interested in this also.

I have a case where I want to loop over the fields in a table, and set the
handlers programmatically. This would be a much simpler effort than to
manually set up hundreds of explicit scripted event handlers in Form Designer.

I found the (non-XFA) field.setAction() method and tried it out:

var doc = event.target;
var f = doc.getField("form1[0].#subform[0].TextField1[0]");
f.setAction("MouseDown", "app.alert('did mouse down')");

This doesn't work. This is consistent with the description in "Converting
Acrobat JavaScript for Use in LiveCycle Designer Forms".

On the other hand, overriding the keystroke handler does work:

f.setAction("Keystroke", "app.alert('did keystroke')");

While I can find this useful, I really need the mouse handlers. This also
might be a mistake, since it conflicts with the document above.

I also tried to access the event script via the XFA accessors, e.g.

var event = TextField1.resolveNode("#event[0]");
app.alert("event: " + event.script.value);
event.script.value = "app.alert('changed exit')";

This "works" in that I see the script and can even modify it, but it does not
change behaviour, which indicates that these XFA fields are likely no longer
being processed.

So, is there any way to dynamically set a field's event handler to something
else in XFA forms? So far it does not seem so.

Perhaps via some sort of loadXML() approach?
rblaa
Registered: Jun 15 2007
Posts: 3
Let's try that again with better formatting:


I am interested in this also.


I have a case where I want to loop over the fields in a table, and set the
handlers programmatically. This would be a much simpler effort than to
manually set up hundreds of explicit scripted event handlers in Form Designer.


I found the (non-XFA) field.setAction() method and tried it out:


var doc = event.target;
var f = doc.getField("form1[0].#subform[0].TextField1[0]");
f.setAction("MouseDown", "app.alert('did mouse down')");



This doesn't work. This is consistent with the description in "Converting
Acrobat JavaScript for Use in LiveCycle Designer Forms".


On the other hand, overriding the keystroke handler does work:


f.setAction("Keystroke", "app.alert('did keystroke')");



While I can find this useful, I really need the mouse handlers. This also
might be a mistake, since it conflicts with the document above.


I also tried to access the event script via the XFA accessors, e.g.


var event = TextField1.resolveNode("#event[0]");
app.alert("event: " + event.script.value);
event.script.value = "app.alert('changed exit')";



This "works" in that I see the script and can even modify it, but it does not
change behaviour, which indicates that these XFA fields are likely no longer
being processed.


So, is there any way to dynamically set a field's event handler to something
else in XFA forms? So far it does not seem so.


Perhaps via some sort of loadXML() approach?