logo
down
shadow

Autocomplete UI, highlight multiple words in tags


Autocomplete UI, highlight multiple words in tags

Content Index :

Autocomplete UI, highlight multiple words in tags
Tag : jquery-ui , By : Ansari
Date : December 18 2020, 12:00 PM

I wish did fix the issue. As per previous post we can override the autocomplete filter methods to create our custom filters.
$.ui.autocomplete.filter = function (array, term) {
    term=term.trim().replace(/\s+/g, '[^]*');// to search multiple words    
    var matcher = new RegExp("(" + term + ")", "i");
    return $.grep(array, function (value) {
        return matcher.test(value.label || value.value || value);
    });
};
function(ul, item) {
    var searchMask = this.element.val().trim();
    var regEx = new RegExp(searchMask, "ig");
    var replaceMask = "<b>$&</b>";
    var html=$(item.label).text(); // manipulating text only
    var splitText = searchMask.split(' ');

    $.each( splitText, function( index, value ){
        html = html.replace(new RegExp(value, "ig"), replaceMask);
    });        

    return $("<li></li>")
        .data("item.autocomplete", item)
        .append($('<div class="item"></div>').html(html))
        .appendTo(ul);
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

how to use rails3-jquery-autocomplete plugin for multiple words autocomplete


Tag : jquery , By : Jason Vance
Date : March 29 2020, 07:55 AM
I wish this helpful for you rails3-jquery-autocomplete plugin? It seems that it doesn't support multiple autocomplete, you need to modify the plugin code!! If you insist on your former ideas, follow my steps.
run bundle show rails3-jquery-autocomplete to get the plugin working directroy mate /lib/autocomplete.rb
define_method("autocomplete_#{object}_#{method}") do
  arr = params[:term].split(",")
  unless params[:term] && params[:term].empty?
    items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{arr[arr.size-1]}%"]).limit(limit).order(order)
  else
    items = {}
end

render :json => json_for_autocomplete(items, method)

How to highlight input words in autocomplete jquery ui


Tag : jquery-ui , By : PatrickSimonHenk
Date : March 29 2020, 07:55 AM
To fix this issue It seems to me you should overwrite the _renderItem method to have custom rendering of the items. The code could be about the following:
$("#studentName").autocomplete({/* all your parameters*/})
    .data("autocomplete")._renderItem = function (ul, item) {
        var newText = String(item.value).replace(
                new RegExp(this.term, "gi"),
                "<span class='ui-state-highlight'>$&</span>");

        return $("<li></li>")
            .data("item.autocomplete", item)
            .append("<div>" + newText + "</div>")
            .appendTo(ul);
    };
var $elem = $("#studentName").autocomplete({/* all your parameters*/}),
    elemAutocomplete = $elem.data("ui-autocomplete") || $elem.data("autocomplete");
if (elemAutocomplete) {
    elemAutocomplete._renderItem = function (ul, item) {
        var newText = String(item.value).replace(
                new RegExp(this.term, "gi"),
                "<span class='ui-state-highlight'>$&</span>");

        return $("<li></li>")
            .data("item.autocomplete", item)
            .append("<div>" + newText + "</div>")
            .appendTo(ul);
    };
}

Ignoring HTML tags to highlight matching words


Tag : javascript , By : christiandsg
Date : March 29 2020, 07:55 AM
Hope this helps I want to replace HTML template content with new one after highlighting the words those match the search input. , Firstly I am sorry for quick tested answer.
Here is your answers:
var reg = new RegExp("[\>][^\<\>.]*"+tag+"[^\<\>.][\<]*","gi");
var reg = new RegExp("[\>][^\<\>.]*"+tag+"[^\<\>.]*[\<]*","gi");
var text = "<div>fireman has killed fire</div>";
text = "<div><highlight>fire</highlight>man has killed <highlight>fire</highlight></div>";

Highlight certain words in input form without using tags?


Tag : javascript , By : Paolo
Date : March 29 2020, 07:55 AM
Any of those help The only way I can think of is to use getBoundingClientRect() and draw an overlay over the box while the user is writting.
getBoundingClientRect() is expensive, but running at user typing speed is no problem actually.

How highlight words jquery ui autocomplete


Tag : jquery , By : Saurabh
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
shadow
Privacy Policy - Terms - Contact Us © scrbit.com