File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Gravity Perks // Advanced Select // Search For Exact Match
3+ * https://gravitywiz.com/documentation/gravity-forms-advanced-select/
4+ *
5+ * By default, Advanced Select will return any item whose label contains the search query. This
6+ * snippet will change the search algorithm to only return items whose label matches the
7+ * search query exactly.
8+ *
9+ * Instruction Video: https://www.loom.com/share/4266734e5ab14870ba6b8bba28d01f68
10+ *
11+ * Instructions:
12+ *
13+ * 1. Install this snippet with our free Custom JavaScript plugin.
14+ * https://gravitywiz.com/gravity-forms-code-chest/
15+ */
16+ gform . addFilter ( 'gpadvs_settings' , function ( settings , gpadvs ) {
17+ settings . score = function ( search ) {
18+ if ( ! search ) {
19+ return function ( ) {
20+ // Item has no search query, return all items
21+ return 1 ;
22+ } ;
23+ }
24+ search = search . toLowerCase ( ) ;
25+ return function ( item ) {
26+ if ( item . text . toLowerCase ( ) === search ) {
27+ // High score for items matching search query exactly
28+ return 1 ;
29+ }
30+ // Zero score for items not matching search query
31+ return 0 ;
32+ } ;
33+ } ;
34+ return settings ;
35+ } ) ;
You can’t perform that action at this time.
0 commit comments