4 Replies Latest reply on Jun 26, 2012 9:23 PM by PeterWindle

    Applying text formatting

    PeterWindle

      Hello again,

      I have a calcualted text field which returns values from a related list, all into one comma separated string eg:

      Let call this field "calc field", for example, it would contain values such as:

       

      Peter, Harry, Lola, Jennifer, Ben, Anita

       

      I would like to highlight one of these names (based on another field) so that if that name is chosen (let's call this field "namefield"), it becomes bold.

       

      eg: when namefield="Ben", the calc shows:

       

      Peter, Harry, Lola, Jennifer, Ben, Anita

       

      anyone know how to do this?

        • 1. Re: Applying text formatting
          nsabel

          This first one is simple and will work except it has some flaws.

           

          Substitute ( table::calcField ; table::nameField ; TextStyleAdd ( table::nameField ; Bold ) )

           

          The better option is more complex see below.

           

          Let ( [

          string = TextFormatRemove ( Test::Calc ) ;

          start = Position ( Test::Calc ; Test::name ; 1 ; 1 ) ;

          size = Length ( Test::name ) ;

          boldText = TextStyleAdd ( Middle ( Test::Calc ; start ; size ) ; Bold )

          ] ;

          Left ( string ; start - 1 ) & boldText & Right ( string ; Length ( string ) - ( start + size - 1 ) )

          )

           

          Change:

          If you use the substitue make sure to add a text format remove to clear out the last bold name. Also the flaws I was talking about are this will bold any occurance so Ben, Benjamin would retrurn Ben, Benjamin.

           

          Substitute ( TextFormatRemove ( table::calcField ) ; table::nameField ; TextStyleAdd ( table::nameField ; Bold ) )

          • 2. Re: Applying text formatting
            taylorsharpe

            I like nsabel's Substitute better, but this is what I worked up.  It is similar to nsabell's let statement and basically does the same thing. 

             

            Let ( [

             

             

            F1 = TextFormatRemove ( List Field ) ; // Peter, Harry, Lola, Jennifer, Ben, Anita

            F2 = Selected Name ;  // Ben

            F3 = Position ( F1 ; F2 ; 1 ; 1 ) ;  // this is the starting position of the highlighted name

            F4 = Middle ( F1 ; F3 ; 9999999 ) ;   // this is the highlighted name and everything to its right

            F5 = Position ( F4 ; "," ; 1 ; 1 ) ;   // this finds the position of the first comma after the highlighted name

            F6 = TextStyleAdd ( Middle ( F1 ; F3 ; F5 ) ; Bold ) ;

            F7 = Left ( F1 ; F3 - 1 ) & F6 & Middle ( F1 ; F3 + F5 ; 999999 )

             

             

            ] ;

             

             

            F7

             

             

            )

            • 3. Re: Applying text formatting
              comment

              It would probably be better to do the highlighting in the original record.

               

              See also:

              http://www.briandunning.com/cf/578

              http://www.briandunning.com/cf/1390

              • 4. Re: Applying text formatting
                PeterWindle

                A HUGE thank you to all who replied to this!

                 

                It's such a simple thing to do for a user, improving the visual interface with a simple calc.

                 

                Thanks again!