Skip to content

Commit 7241ade

Browse files
authored
gpadvs-search-exact-match.js: Added snippet to enable exact match functionality with GP Advanced Select.
1 parent 2748bcb commit 7241ade

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
} );

0 commit comments

Comments
 (0)