Giter Site home page Giter Site logo

Comments (3)

melloware avatar melloware commented on July 23, 2024 1

how about highlightSelector as a better name since its really a selector?

from primefaces.

melloware avatar melloware commented on July 23, 2024

not sure about the name queryHighlightFilter but i get the idea. It can be span by default for most scenarios and overridden if necessary.

from primefaces.

melloware avatar melloware commented on July 23, 2024

For now here is a MonkeyPatch to do what you want for .ui-autocomplete-item-value

if (PrimeFaces.widget.AutoComplete) {
    PrimeFaces.widget.AutoComplete.prototype.showSuggestions = function(query) {
        this.items = this.panel.find('.ui-autocomplete-item');
        this.items.attr('role', 'option');

        if (this.cfg.grouping) {
            this.groupItems();
        }

        this.bindDynamicEvents();

        var $this = this,
            hidden = this.panel.is(':hidden');

        if (hidden) {
            this.show();
        } else {
            this.alignPanel();
        }

        // #8717 always clear list before trying to fill it
        if (this.cfg.forceSelection) {
            this.currentItems = [];
        }

        if (this.items.length > 0) {
            var firstItem = this.items.eq(0);

            //highlight first item
            if (this.cfg.autoHighlight && firstItem.length) {
                this.highlightItem(firstItem, true);
                this.changeAriaValue(firstItem[0]);
            }

            //highlight query string
            if (query.length > 0) {
                var cleanedQuery = query.trim().replaceAll(/(\s+)/g, ' ');
                if (cleanedQuery.length > 0) {
                    var queryParts = cleanedQuery.split(' ');
                    for (var i = 0; i < queryParts.length; i++) {
                        queryParts[i] = PrimeFaces.escapeRegExp(queryParts[i]);
                    }
                    var re = new RegExp('(' + queryParts.join('|') + ')', 'gi');
                    var isCustomContent = this.panel.children().is('table');
                    var queryResults = isCustomContent ? this.panel.children().find('.ui-autocomplete-item-value') : this.items;
                    queryResults.filter(':not(.ui-autocomplete-moretext)').each(function() {
                        var item = $(this);
                        var escape = $this.cfg.escape;
                        var text = escape ? item.html() : item.text();
                        var escaped_re = escape ? /${PrimeFaces.escapeHTML(text)}/g : /${text}/g;
                        text = text.replace(escaped_re, '$&');
                        item.html(text.replace(re, '<span class="ui-autocomplete-query">$&</span>'));
                    });
                }
            }

            if (this.cfg.forceSelection) {
                this.items.each(function(i, item) {
                    $this.currentItems.push($(item).attr('data-item-label'));
                });
            }

            //show itemtip if defined
            if (this.cfg.autoHighlight && this.cfg.itemtip && firstItem.length === 1) {
                this.showItemtip(firstItem);
            }

            this.displayAriaStatus(this.items.length + this.cfg.resultsMessage);
        } else {
            if (this.cfg.emptyMessage) {
                var emptyText = '<div class="ui-autocomplete-empty-message ui-widget">' + PrimeFaces.escapeHTML(this.cfg.emptyMessage) + '</div>';
                this.panel.prepend(emptyText);
            } else if (!this.cfg.hasFooter) {
                this.panel.hide();
            }

            this.input.removeAttr('aria-activedescendant');
            this.displayAriaStatus(this.cfg.ariaEmptyMessage);
        }
    }
};

from primefaces.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.