dojo.provide("umat.form.FilteringSelect");

dojo.require("dijit.form.FilteringSelect");

dojo.declare(
	"umat.form.FilteringSelect",
	[dijit.form.FilteringSelect],
	{

		invalidMessage: "El valor introduït no és vàlid.",

		// @Override example
		_openResultList: function(/*Object*/ results, /*Object*/ dataObject){
   			// do my stuff, then...
   			this.inherited("_openResultList", arguments);
		},

		_startSearch: function(/*String*/ key){
			if(!this._popupWidget){
				this._popupWidget = new dijit.form._ComboBoxMenu({
					onChange: dojo.hitch(this, this._selectOption)
				});
			}

			// create a new query to prevent accidentally querying for a hidden value from FilteringSelect's keyField
			var query=this.query;
			this._lastQuery=query[this.searchAttr]="*"+key.removeAccents()+"*";
			var dataObject=this.store.fetch({queryOptions:{ignoreCase:this.ignoreCase, deep:true}, query: query, onComplete:dojo.hitch(this, "_openResultList"), start:0, count:this.pageSize});
			function nextSearch(dataObject, direction){
				dataObject.start+=dataObject.count*direction;
				// #4091: tell callback the direction of the paging so the screen reader knows which menu option to shout
				dataObject.direction=direction;
				dataObject.store.fetch(dataObject);
			}
			this._nextSearch=this._popupWidget.onPage=dojo.hitch(this, nextSearch, dataObject);
		}

	}
);


