cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
phokanson
Level: Powered On

HIghlighting found search values within an HTMLText field

I have a vexing problem I'm trying to solve.  I have field where the user can type in strings to search for within a field that is part of a gallery.  The gallery contains several fields.  The first is called Name.  Name contains a value such as 42-009-28443-00-01.  I want the user to be able to type "42 009 00 2844", and the corresponding Name fields within the gallery should highlight the pieces of the Name field that match what the user typed.  So, for the example, all of the gallery entries with Name fields that contain 42 would highlight that matching part of the name such as 42-T24-00-09-01, or 37-420075-009-01.

 

Because the Name field within the datacard is an HTMLText field, highlighting can be accomplished using <b style="color:#0000FF">42</b>.    In the OnChange of the Search text field I currently have the following:

 

If(Len(txtSearchText.Text) >= 3,
Collect(Pieces, TrimEnds( Split(txtSearchText.Text, " " )));
ForAll(Pieces,
Replace(
Name2.HtmlText,
Find(
Lower(Result),
Lower(Name2.HtmlText)
),
Len(Result),
"<b style="&Char(34)&"color:#0000FF"&Char(34)&">" & Mid(Name2.HtmlText,
Find(
Lower(Result),
Lower(Name2.HtmlText)),Len(Result)) & "</b>"
))
);

 

txtSearchText.Text control contains the search string ("42 009 00 2844" from example above).  Name2 control contains the text "42-009-28443-00-01".  The result I am wanting to see is for Name2 to contain 42-009-28443-00-01.

 

In my frustration in trying to get this running, I've also tried:

 

Collect(Pieces, TrimEnds( Split(txtSearchText.Text, " " )));
Clear(Subsitutes);
ForAll(Pieces,
Collect(Subsitutes, {Replacement: "<b style="&Char(34)&"color:#0000FF"&Char(34)&">" &
Mid(Name2.HtmlText,
Find(Lower(Result),Lower(Name2.HtmlText)),
Len(Result)) & "</b>", Target: Result})
);

ForAll(Subsitutes,
Replace(Name2.HtmlText,
Find(Lower(Target),Lower(Name2.HtmlText)),
Len(Target), Replacement);
)

 

Figuring that if I could combine the string to search for with it's replacement with in a collection, I would have a better result....I didn't.

 

Any thoughts you may have on this would be appreciated.

3 REPLIES 3
Super User
Super User

Re: HIghlighting found search values within an HTMLText field

(deleted)

chrisog
Level 8

Re: HIghlighting found search values within an HTMLText field

Hi @phokanson,

 

I think i have a solution to this that may work using the Substitute function. 

 

I used the placeholder HTML text, "Show your <b><font color=blue>HTML</font></b> text here." and wanted the word "Show" to be shown in red bold. To do this, I created a text input for the user to enter the word "Show". Then I changed the HTML text function to the following:

 

Substitute("Show your <b><font color=blue>HTML</font></b> text here.",TextInput1.Text,"<b><font color=red>" &  TextInput1.Text & "</font></b>")

 

I have checked this and it gives the desired result. You should be able to apply this to your HTML text.

chrisog
Level 8

Re: HIghlighting found search values within an HTMLText field

Hi @phokanson,

 

Having thought about this a bit more, you will have to look at a slightly more complex formula to be able to search for the multiple substrings that the user may search for. I have a sample of the formula you will require:

 

ClearCollect(splitSearchValue,Split(TextInput1.Text,"-"));ClearCollect(myHTML,"Show your <b><font color=blue>HTML</font></b> text here.");ForAll(splitSearchValue,Collect(myHTML,Substitute(Last(myHTML).Value,Result,"<b><font color=red>" & Result & "</font></b>")))

 

From here, you will need to set the HTML text to display Last(myHTML).Value

 

Please give this a try and let me know if it does what you need it to.

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,368)