Click to Win!

As the readership of this blog goes up, I feel it is only right that the readers be rewarded.

By opening and completing the attached PDF, you get your chance to claim a reward*


Interesting xfa.event properties

Today’s sample has some interesting script code that makes use of xfa.event properties during the change event.  The change event on the Amount field shows how you can make use of the change, selStart and selEnd properties.  selStart and selEnd tell you the start and end positions of where the input (represented by xfa.event.change) will be inserted in the old text (xfa.event.prevText).  When no text is selected, selStart and selEnd have the same value.  When the user has highlighted/selected several characters of text, selStart and selEnd will point to the start and end of that range.  In the Amount field of the sample, the change event script modified selStart and selEnd so that the users input would always be inserted to the right of the decimal — preventing them from entering a value greater than 1.

This can also have a more useful application.  For example, the widgets on PDF forms do not support overstrike mode.  You can implement overstrike by adjusting selEnd to include the character to the right of the insert point.  This sample script will cause a field to be in overstrike mode:

 myForm.test[0].testField::change – (JavaScript, client)
// Don’t overstrike if the <control> key is down — likely means they’re doing a paste
if (!xfa.event.modifier)
  // Don’t overstrike if they’ve selected text (selStart != selEnd)
  if (xfa.event.selStart == xfa.event.selEnd)

Happy April.

* Assuming that you have also entered some other contest that gives you a chance at winning a prize.

2 Responses to Click to Win!

  1. An says:

    Funny, funny :) I haven’t commented before, but I just wanted to say thank you for all of your hard work. I’m working on a pdf with 2893282389023 dynamic criteria right now and your blogs on the validation scripts have really increased my form’s efficiency.- An

  2. An:Thanks for commenting.Glad to help.John