Community Alums
Not applicable

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

Comments
Peter Przenniac
Tera Expert

Hi, on what level did you create this ClientScript?

Community Alums
Not applicable

Hi Peter,

I dont follow - you mean like type (if so this is Client Script onLoad).

Can you specify your question 🙂 

 

Cheers,

Joro

Peter Przenniac
Tera Expert

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 

Community Alums
Not applicable

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

Community Alums
Not applicable

JoroKlifov1_0-1680783938908.png

 

Version history
Last update:
‎09-19-2021 11:52 AM
Updated by:
Community Alums