Ticket #6390 (closed defect: fixed)

Opened 8 months ago

Last modified 5 months ago

[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

6390.patch (1.0 kB) - added by haysmark 8 months ago.
Fixes #6390. Expands filtering capabilities of _ComboBoxDataStore.

Change History

Changed 8 months ago by doughays

  • owner set to haysmark
  • milestone set to 1.2

Changed 8 months ago by haysmark

Fixes #6390. Expands filtering capabilities of _ComboBoxDataStore.

Changed 8 months ago by haysmark

  • status changed from new to assigned
  • summary changed from Can't search all in ComboBox / FilteringSelect to [patch] Can't search all in ComboBox / FilteringSelect

Changed 5 months ago by bill

  • status changed from assigned to closed
  • resolution set to fixed

(In [14220]) Fixes #6390: Can't search all in ComboBox? / FilteringSelect? Patch from Mark Hays. !strict

Note: See TracTickets for help on using tickets.