Search by value and display another in Dojo FilteringSelect

I use the dojo FilteringSelect element together in a Zend form, but I cannot get it to work the way I want. I have a store with three fields id , label , name . The shortcut will be used for the drop-down menu and should also be used for searching, and name should be used to display te inside the field. The problem is that I cannot find a way to make this behavior work.

Setting labelAttr to label shows it in the drop-down list, but the searchAttr attribute controls both the search and the display in the input field after selecting a value. I need to find the label field, since it is a collection of several fields, but maps the value to name , is this possible?

EDIT: @RichardAyotte The Dijit FilteringSelect widget uses dojo.data.store, which is basically a javascript object, where each element is also an object with many parameters. You can set two special parameters in the repository: labelAttr and searchAttr , which will define a couple of behaviors. FilteringSelect is bound to the INPUT field in which you can search. If you click on the button, a list of options will open, for example . Here it shows everything that you defined as labelAttr. Now, if you type a field, it will search in the store using what is defined in the searchAttr field. He also used the label value to display inside the input as soon as you select something from the list (you can check it here http://dojotoolkit.org/reference-guide/1.9/dijit/form/FilteringSelect.html#displaying-rich -text-menu-labels-with-labelattr-and-labeltype )

What I wanted to do was to "untie" the searchAttr field into two different search fields, and the other to display inside the input. AFAICT is not possible and I will have to extend the FilteringSelect object

+7
dojo zend-framework
source share
1 answer

You can do such things with AOP. See dojo / aspect .

caveat : adding recommendations for the private _announceOption function.

 var countryField = new FilteringSelect({ label: 'Country' , name: 'country_id' , searchAttr: 'name' , labelAttr: 'label' , store: new CountryStore() }); aspect.around(countryField, '_announceOption', function(origFunction) { return function(node) { this.searchAttr = 'label' var r = origFunction.call(this, node); this.searchAttr = 'name' return r; } }) 
+1
source share

All Articles