Using FormatResult and underline feature together

2,968 views
Skip to first unread message

dand...@geac.com

unread,
Mar 13, 2013, 12:34:53 PM3/13/13
to sel...@googlegroups.com
I want to use the FormatResult feature to format the display but when I type characters to search for, the correct items are shown in the list but the characters are not underlined like they are if I do not use FormatResult. Is there a way to get both features to work together?

Thanks for any help you can provide!

Dave Anderson

Igor Vaynberg

unread,
Mar 13, 2013, 1:28:14 PM3/13/13
to sel...@googlegroups.com
select2 exports the function it uses to do the underlining here:

window.Select2.util.markMatch

here is how it is used in the default formatter:

formatResult: function(result, container, query, escapeMarkup) {
var markup=[];
markMatch(result.text, query.term, markup, escapeMarkup);
return markup.join("");
},

you can do the same but you have to reference it via the export above.

-igor
> --
> You received this message because you are subscribed to the Google Groups "select2" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
> To post to this group, send email to sel...@googlegroups.com.
> Visit this group at http://groups.google.com/group/select2?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

dand...@geac.com

unread,
Mar 13, 2013, 2:51:17 PM3/13/13
to sel...@googlegroups.com, dand...@geac.com
Thanks Igor for your prompt response! I was able to do what you suggested but the issue that I was trying to solve was actually that your markMatch function adds span tags with the class around the matches to underline them but I am using html tags to format my information and when you add a span around the search terms within the html tags (ie. if I search for ta, it finds table) and the formating no longer works because the begin tag is invalid now. Not sure if you have a workaround for this or maybe plans to update the markMatch function to ignore matches within tags <> in the future? Thanks again!

Dave

Igor Vaynberg

unread,
Mar 13, 2013, 3:04:11 PM3/13/13
to sel...@googlegroups.com, dand...@geac.com
you have to run markMatch on your text before you construct html. if
you receive html from server then you need to roll your own markMatch.

-igor

On Wed, Mar 13, 2013 at 11:51 AM, <dand...@geac.com> wrote:
> Thanks Igor for your prompt response! I was able to do what you suggested but the issue that I was trying to solve was actually that your markMatch function adds span tags with the class around the matches to underline them but I am using html tags to format my information and when you add a span around the search terms within the html tags (ie. if I search for ta, it finds table) and the formating no longer works because the begin tag is invalid now. Not sure if you have a workaround for this or maybe plans to update the markMatch function to ignore matches within tags <> in the future? Thanks again!
>
> Dave
>
Reply all
Reply to author
Forward
0 new messages