Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Formapi issue
JoshProx
I am trying to escape " and \n using formapi. This is my code -
function fnCheck (path)
{
var val = path.getValue();
var val1 = val.replace(new RegExp("\\n", "g"), "<br />");
var val2 = val1.replace(new RegExp("\"", "g"), "\\\"");
var val3 = val2.replace(new RegExp("\\\\", "g"), "\\");
path.setValue(val3);
}
This method is called in onItemChange and keeps on adding \\ to already escaped strings. This line var val3 = val2.replace(new RegExp("\\\\", "g"), "\\"); which is intended to remove \\ from the already escaped strings doesn't work.
Any feedback will be much appreciated.
Find more posts tagged with
Comments
JoshProx
I wrote some dirty javascript code for handling this case -
function fnCheck (path)
{
var val = path.getValue();
val = val.replace(new RegExp("\\n", "g"), "<br />");
val = val.replace(new RegExp("\"", "g"), "\\\"");
var out = "\\\\";
var add = "\\";
while (val.indexOf(out)>-1) {
var pos= val.indexOf(out);
val = "" + (val.substring(0, pos) + add +
val.substring((pos + out.length), val.length));
}
path.setValue(val);
}