Using stripHTML() but keep line breaks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 08:31 AM
I'm definitely not great with regex. I'm trying to find a solution to covert html field to a multi-line field in a record producer to a record but all the regex I've looked at some posted don't seem to work right. I tried the stripHTML() function but that takes out line breaks which I will need to keep.
I've tried the below to get closer but it's still shows <p></p> and <a></a> in the field. Any options to remove these?
var desc = g_form.getValue(producer.description);
var cleanDesc = desc.replace(/\n/g, '<br>');
g_form.setValue('desciption', cleanDesc);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2023 08:47 AM - edited ‎07-10-2023 09:09 AM
Hi @KB15
Use below code , it will remove the p and a tags
var desc = g_form.getValue(producer.description);
cleanDesc= desc.replace(/<(?!br\s*\/?)[^>]+>/g, "");
g_form.setValue('desciption', cleanDesc);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2023 08:03 AM
I'm not sure if this is by design in the HTML field or no but I still get the anchor and paragraph tags.
Shows up in the raw code view in the editor exactly as it does in the multi text field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2023 09:14 AM
Hi @KB15
Try again, there was a typo in script. Description name was wrong in last line
var desc = g_form.getValue(producer.description);
cleanDesc= desc.replace(/<(?!br\s*\/?)[^>]+>/g, "");
g_form.setValue('description', cleanDesc);
Also i tried in background script and it is working as expected
Sample input -
this is my <b>string</b> and it\'s pretty cool<br />isn\'t it?<br>Yep, it is. <strong>More HTML tags</strong>
Output received after running script -
this is my string and it's pretty cool<br />isn't it?<br>Yep, it is. More HTML tags
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2023 02:21 PM
Don't think that's the issue otherwise I would have had a blank description. It's something with the HTML editor and the record producer. Background script behaves differently.