Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#5219 closed feature (fixed)

Autocomplete: Support for accent-folding

Reported by: jzaefferer Owned by:
Priority: major Milestone: 1.8.3
Component: ui.autocomplete Version: 1.8rc2
Keywords: Cc:
Blocked by: Blocking:

Description

Explanation of accent-folding and an example for YUI: http://www.alistapart.com/articles/accent-folding-for-auto-complete/

Autocomplete should support adding accent-folding on top.

Change History (7)

comment:1 Changed 7 years ago by lambacck

It does. I'm doing it.

You want your source to be a function. See the "Combo Box" example for highlighting and the "Remote With Caching" for searching through an object list for values to display. You just need to change the match and highlight to be accent insensitive.

comment:2 Changed 7 years ago by lambacck

The if condition is also probably needs tweaking. It currently says:

if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
    var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
    response($.grep(cache.content, function(value) {
        return matcher.test(value.value)
    }));
}

It should be:

if (new RegExp($.ui.autocomplete.escapeRegex(cache.term)).test(request.term) && cache.content && cache.content.length < 13) {
    var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
    response($.grep(cache.content, function(value) {
        return matcher.test(value.value);
    }));
    return;
}

Note that cache.term in the if condition is now wrapped in a call to $.ui.autocomplete.escapeRegex to match the matcher RegExp. Also the original bug is fixed by adding a return to the if block.

Also matcher tests value.value, this is a deviation from how the list of object works in the autocomplete itself. It uses:

return matcher.test( value.label || value.value || value );

comment:3 Changed 7 years ago by lambacck

Wrong bug for that last comment.

comment:4 Changed 7 years ago by scottgonzalez

Added a demo in /demos/autocomplete/folding.html in 6a59746d1d97cb24bafe50c1434d9398be9c7585.

comment:5 Changed 6 years ago by scottgonzalez

  • Milestone changed from 1.next to 1.9
  • Resolution set to fixed
  • Status changed from new to closed

Added a link to the demo in 5debdb0. I also built an extension that can be loaded after the plugin to automatically support accent folding when using arrays as the source; it's available in my jQuery UI Extensions repo (source, demo).

comment:6 Changed 6 years ago by scottgonzalez

  • Milestone changed from 1.9 to 1.8.3

comment:7 Changed 6 years ago by Scott González

Autocomplete: Added link to accent folding demo. Fixes #5219 - Autocomplete: Support for accent-folding.

Changeset: 5debdb08d7702e9c04b4efa883c68d350576d710

Note: See TracTickets for help on using tickets.