- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 09-19-2021 11:52 AM
I had an use case, where I had to escape all special characters, but still, only to ignore/replace them simultaneously the user is typing, instead of entering everything, and the system does this after you click away.
Usually we use onChange CSJS for that but here this was not applicable. So I had to think of a way to achieve that, while "remembering" the values (keystrokes) entered before that...
The answer is quite simple - closures !
Here is an example of a client side JS doing exactly that. You can use a system property , where you can set all charachters you want to be escaped and so forth
This is just a working example of the above mentioned on "description" field.
Hope this might help, if you need similar or same funtionality .
function onLoad() {
var control = g_form.getControl('description');
Event.observe(control, 'input', function(e) {
var oldInputVal = e.target.defaultValue;
var newInputVal = e.target.value;
var regexSpecialChars = /\/|\\|\"|;|<|>|\||\t|~|#|\*|:|\?|{|}|\s/gm;
var regexMandatoryChars = /.*_{1}.*_{1}\d*/gm;
var oldInput = (function () {
var i = oldInputVal;
return {
get: function () {
return i;
},
set: function (val) {
i = val;
}
};
})();
var userVal = newInputVal.replace(regexSpecialChars, "_");
if(!regexMandatoryChars.test(userVal)) userVal = userVal.replace(/\s/, "_");
if(regexSpecialChars.test(e.data)) userVal = userVal.replace(/__/, "_");
oldInput.set(userVal);
g_form.setValue('description', oldInput.get());
});
}
Cheers!
Joro
- 2,436 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, on what level did you create this ClientScript?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Peter,
I dont follow - you mean like type (if so this is Client Script onLoad).
Can you specify your question 🙂
Cheers,
Joro
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
ClientScript on Catalogue item trowing error on SP with Event.observe, so question is, if you create ClientScript on RITM level? thanks for quick response! Appreciate
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
For RITM - it should work as well, but on the portal - not sure. Have you unchecked Isolate Script in the Client Script ? If it's set to true - wont work for sure on protal + set the type to All
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content