Ticket #6390 (closed defect: fixed)
[patch] Can't search all in ComboBox / FilteringSelect
| Reported by: | guest | Owned by: | haysmark |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2 |
| Component: | Dijit | Version: | 1.1.0 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
ComboBox? (also FilteringSelect?) doesn't allow search all. Ticket #5281 requested a way of choosing whether to search from the start of the string, at the end, or both. The attribute queryExpr was added to facilitate this.
However, after the implementation, the ComboBox?'s fetch function http://trac.dojotoolkit.org/browser/dijit/trunk/form/ComboBox.js?rev=13252#L984 can only replace the first of the asterisks (when queryExpr = "*${0}*"), resulting in incorrect searches (though "begins with" or "ends with" should both have been fine).
The fetch function:
fetch: function(/* Object */ args){
// summary:
// Given a query and set of defined options, such as a start and count of items to return,
// this method executes the query and makes the results available as data items.
// Refer to dojo.data.api.Read.fetch() more details.
//
// description:
// Given a query like
//
// | {
// | query: {name: "Cal*"},
// | start: 30,
// | count: 20,
// | ignoreCase: true,
// | onComplete: function(/* item[] */ items, /* Object */ args){...}
// | }
//
// will call `onComplete()` with the results of the query (and the argument to this method)
// convert query to regex (ex: convert "first\last*" to /^first\\last.*$/i) and get matching vals
var query = "^" + args.query.name
.replace(/([\\\|\(\)\[\{\^\$\+\?\.\<\>])/g, "\\$1")
.replace("*", ".*") + "$",
matcher = new RegExp(query, args.queryOptions.ignoreCase ? "i" : ""),
items = dojo.query("> option", this.root).filter(function(option){
return (option.innerText || option.textContent || '').match(matcher);
} );
var start = args.start || 0,
end = ("count" in args && args.count != Infinity) ? (start + args.count) : items.length ;
args.onComplete(items.slice(start, end), args);
return args; // Object
// TODO: I don't need to return the length?
},
I believe the fix would simply be to change line 1006 from:
.replace("*", ".*") + "$";
to:
.replace(/\*/g, ".*") + "$";
Attachments
Change History
Note: See
TracTickets for help on using
tickets.