How is dojo.FilteringSelect configured to match wildcards?

Below is a sample filter selected using user data. My goal is to match the wilcard to the displayed values. for example, if the user enters "son", the drop-down matches will be "homer simpSON" and "carl calSON". By default, the match will only be at the beginning of the label.

I tried changing dijit.byId ('userselect'). searchAttr, but setting it to anything but a string causes bad behavior.

<input id="userselect"> <script type="text/javascript"> dojo.require("dijit.form.FilteringSelect"); dojo.require("dojo.data.ItemFileReadStore"); var user_data = { "itentifier":"user_id", "label":"label", "items":[ {"first_name":"Waylon","last_name":"Smithers","label":"Waylon Smithers","user_id":7} ,{"first_name":"Carl","last_name":"Carlson","label":"Carl Carlson","user_id":6} ,{"first_name":"Homer","last_name":"Simpson","label":"Homer Simpson","user_id":4} ,{"first_name":"Lenny","last_name":"Leonard","label":"Lenny Leonard","user_id":5} ,{"first_name":"Montgomery","last_name":"Burns","label":"Montgomery Burns","user_id":8} ] }; dojo.addOnLoad(function() { var userStore = new dojo.data.ItemFileReadStore({ //url: "/user/lookup", data: user_data }); var filteringSelect = new dijit.form.FilteringSelect({ id: "userselect", name: "userselect", store: userStore, searchAttr: 'label' //["first_name", "last_name", "oasis"] }, "userselect"); }); </script> 
+4
source share
2 answers

You need to set queryExpr and set autoComplete to false

 var filteringSelect = new dijit.form.FilteringSelect({ id: "userselect", name: "userselect", store: userStore, searchAttr: 'label', queryExpr: '*${0}*', autoComplete: false },"userselect"); 

Dojo documentation for queryExpr :

Indicates which request is sent to the data warehouse based on what the user typed. Changing this expression will change whether the results will be just exact matches, a β€œstart from" match, etc. dojo. request expression template .data. $ {0} will replace user text. * used for wildcards.

${0}* means "starts with"
*${0}* means "contains"
${0} means "is"

+5
source

Take a look at queryExpr

0
source

Source: https://habr.com/ru/post/1309350/


All Articles