Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
During keystroke entry one can use the "change" property of the event object.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
There is, actually. It's an internal function called AFMergeChange.
You can use it like this:
var newValue = AFMergeChange(event);
Copy link to clipboard
Copied
Thanks, I will look into that.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now