Opened 7 years ago

Closed 4 years ago

#16779 closed enhancement (patchwelcome)

_SearchMIxin:allow plugin custom query function

Reported by: ebengtso Owned by:
Priority: undecided Milestone: 1.13
Component: Dijit - Form Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

dijit/form/_SearchMixin only queries for a single attribute (searchAttr) on a dojo/store, yet if you allow a custom function to be plugged in, then one could query for all attributes on a store.

so if in my code I call such function, the _SearchMixin._startSearch will call my factory to create a query, and it will pass along to the store.query:

_SearchMixin.setQueryFunctionFactory(function(regex) { return function(object) {

for ( var key in object) {

if(regex.test(object[key])) {

return true;

} return false;

}

});

Attachments (2)

_SearchMixin.js (9.6 KB) - added by ebengtso 7 years ago.
SearchBox.js (2.2 KB) - added by ebengtso 7 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by bill

Component: GeneralDijit - Form
Owner: set to Douglas Hays
Summary: allow plugin custom query function to dijit/form/_SearchMixin_SearchMIxin:allow plugin custom query function

The idea of a static _SearchMixin.setQueryFunctionFactory() method seems strange to me, since changing that would affect all classes, not just your own subclass. Maybe a doQuery() type method that a subclass can override makes sense.

Changed 7 years ago by ebengtso

Attachment: _SearchMixin.js added

Changed 7 years ago by ebengtso

Attachment: SearchBox.js added

comment:2 Changed 7 years ago by ebengtso

Code called by the application, where this.filterBox is an instance of the SearchBox?

this.filterBox.setQueryFunctionFactory(function(regex) { 
					return function(object) {
				        if(!regex.test)
				        {
				        	return true;
				        }
						for ( var key in object)
					    {
					        if( regex.test(object[key]))
					        {
					            return true;
					        }
					    }
				        return false;
					};
				}); 

Last edited 7 years ago by ebengtso (previous) (diff)

comment:3 Changed 7 years ago by ebengtso

I've attached the modified _SearchMixin, and the code called by the application to set the custom query. The dojox/mobile/SearchBox has not been modified.

_SearchMixin will check if there is a custom query factory, if there is one, then it calls it with the regexp as parameter, otherwise it will work as before.

the application is responsible to provide a factory function. It calls setQueryFunctionFactory with a function (1) that takes a regular expression. _SearchMixin will call the factory function (1) which returns a function (2) that uses the regexp to check all the attributes of the given object.

The function (2) will be later called by dojo/store/util/SimpleQueryEngine

Last edited 7 years ago by ebengtso (previous) (diff)

comment:4 Changed 7 years ago by bill

OK. I don't see any reason to have a setQueryFunctionFactory() method, but perhaps a queryFactory() method that a subclass or instance can override makes sense.

comment:5 Changed 7 years ago by ebengtso

ok makes sense.

comment:6 Changed 6 years ago by Douglas Hays

Owner: Douglas Hays deleted
Status: newassigned

comment:7 Changed 6 years ago by Douglas Hays

Status: assignedopen

comment:8 Changed 4 years ago by dylan

Milestone: tbd1.12
Resolution: patchwelcome
Status: openclosed

This will need some work. If @ebengtso is still interested in this, please submit an updated pull request per the contributing guidelines, https://github.com/dojo/dojo/blob/master/CONTRIBUTING.md Thanks!

Note: See TracTickets for help on using tickets.