Forum Discussion

edcooper's avatar
edcooper
Qrew Assistant Captain
7 years ago

Strip html from formula text field

The first field on my edit form is "Organization".
This field is set as the field for the form title.
It is a rich text field.
Problem is that the form title displays the name of the organization in the title with all the html code. Yuck.
I'd like to create a formula text field that will read the contents of the Organization field but strip all the html thereby producing 'normal' text.

7 Replies

  • I was looking to do the same thing here and stumbled across this post.  I figured I would post this for future users.  It's cumbersome but appears to work.  I just went up to 3 nonspecific tags here just to keep this relatively short but my actual formula has a lot more.


    var text Note = ToText([Your Rich Text Field Name]);

    //specific tags - can replace them all in note instead of one at a time
    var text AST= SearchAndReplace($NOTE,"<br />","");
    var text BST= SearchAndReplace($AST,"<p>","");
    var text CST= SearchAndReplace($BST,"</p>","");
    var text DST= SearchAndReplace($CST,"<strong>","");
    var text EST= SearchAndReplace($DST,"</strong>","");
    var text FST= SearchAndReplace($EST,"<ol>","");
    var text GST= SearchAndReplace($FST,"</ol>","");
    var text HST= SearchAndReplace($GST,"<li>","");
    var text IST= SearchAndReplace($HST,"</li>","");
    var text JST= SearchAndReplace($IST,"</span>","");
    var text KST= SearchAndReplace($IST,"&nbsp;"," ");

    var text NoteNew = $KST;

    //Glossary
    //SPT = Start Position Tag
    //EPT = Eng Position Tag

    // 1st Tag (A)
    var number ASPT = (Length(Left($NoteNew,"<")))+1;
    var number AEPT = Length(Left($NoteNew,">"))+1;
    var number ALength = $AEPT-$ASPT+1;
    var text ATag = Mid($NoteNew, $ASPT, $Alength);
    var text ANote = SearchAndReplace($NoteNEw,$ATag,"");
    //2nd Tag (B)
    var number BSPT = (Length(Left($ANote,"<")))+1;
    var number BEPT = Length(Left($ANote,">"))+1;
    var number BLength = $BEPT-$BSPT+1;
    var text BTag = Mid($ANOTE, $BSPT, $Blength);
    var text BNote = SearchAndReplace($ANote,$BTag,"");
    //3nd Tag (C)
    var number CSPT = (Length(Left($BNote,"<")))+1;
    var number CEPT = Length(Left($BNote,">"))+1;
    var number CLength = $CEPT-$CSPT+1;
    var text CTag = Mid($BNOTE, $CSPT, $Clength);
    var text CNote = SearchAndReplace($BNote,$CTag,"");
    //Add more as needed

    $CNote
  • Can you please share a screenshot of the Organization field? So, I can see the formatting of that field or what formatting you have applied in that rich-text field?

    Thanks,
    Gaurav
    • edcooper's avatar
      edcooper
      Qrew Assistant Captain
      I've gone back to formatting the Organization field as a text field. Thanks anyway. Spent too much time on this already.
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    (Note Tested)

    Try creating a formula text field to mirror your [Organization] field.
    Use the formula

    ToText([Organization])

    That might work, but i bet it will still get some weird stuff.
    • edcooper's avatar
      edcooper
      Qrew Assistant Captain
      Didn't produce a different result.
      Thanks anyway.
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      Ed, what field type was that formula field?  If it was a formula Rich text field can you try a field type of formula text and not formula rich text.

      You will then see code like this.

      <span style="color:#FFFF00;"><span style="font-size:11px;"><span style="font-family:tahoma,geneva,sans-serif;"><span style="background-color:#FF0000;">hello</span></span></span></span>

      Now, if your users have gone crazy with formatting it will be difficult to parse out the actual words.  In my case my field said "hello", and I had lots of formatting.

      But if the formatting is standard and you post the resulkant HTML code like i did, we may be able to write a formula to parse out the actual words.
    • edcooper's avatar
      edcooper
      Qrew Assistant Captain
      I've decided it's not worth the effort. Changed field type back to text. I appreciate your effort.