Client Script OnChange as the user types
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 12:45 PM
We are looking for a way to validate the text in a string field as the user is typing via regex. We are using an OnChange Client Script, but the function does not run until the field on the form loses focus. We're looking to trigger the OnChange event every time a user types a character into the field. Is there way to do this without forcing the script to run in a loop?
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 12:55 PM
If you're doing this on a standard form you can attach a keypress event to the field control. Here is an example from SNGuru that I've used in the past.
https://www.servicenowguru.com/scripting/client-scripts-scripting/maximum-length-large-string-fields-servicenowcom/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 01:40 PM
Thank you for the quick reply. It doesn't appear that getControl works properly on a service portal form (returns null). Do you know of any similar options on a portal form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 02:20 PM
Yeah, the forums are littered with posts from people complaining about the lack of 'getControl' in the Service Portal. Unless you're working with a custom widget (which I'm guessing you aren't because you're using 'onChange' client scripts) this just isn't possible at the moment. You're going to have to use the 'onChange' event instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2018 06:18 PM
Just checking on on this one. Has this question been answered or is there more information I can help you with? If it's been answered, please mark the answer above as the correct one so people know this has been taken care of. Thanks!
