Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Keystroke script: get current updated value

Advocate ,
Oct 17, 2017 Oct 17, 2017

I'm trying to validate a keystroke entry based on the text already entered. I can get the value before the change was made, but I can't figure out how to tell the value that includes the changes (i.e. I need to accept or reject the keystroke based on the entire updated field contents).  I'm sure I've done this in the past, but I can't find an example of it.

Is there an event property which shows the full value with changes included?

TOPICS
Acrobat SDK and JavaScript
956
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 17, 2017 Oct 17, 2017

During keystroke entry one can use the "change" property of the event object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 17, 2017 Oct 17, 2017

Thanks, but I don't think that's what I'm looking for.

What I need is if the field contains '456', and the user selects the '56' and types '9', I want (what will be) the new value '49' The change value seems to be only the entered character (9 in this case).

Is what I'm looking for not available directly? I am guessing I can get what I need by checking the event selection values, and parse the current value with the change value, but I was hoping there was a property I could access which has the value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 17, 2017 Oct 17, 2017

So, this is what I ended up with to check for the current change value, and it seems to work as I expected.

function getCurrentChangeValue() {

  var s = event.selStart

  var e = event.selEnd

  var value = event.value

  var c = event.change

  value = value.substr(0, s) + c + value.substr(e)

  return value

}

If there is a built in property to do this, I'd rather use that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2017 Oct 17, 2017

There is, actually. It's an internal function called AFMergeChange.

You can use it like this:

var newValue = AFMergeChange(event);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 18, 2017 Oct 18, 2017
LATEST

Thanks, I will look into that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines