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 Wiz // Gravity Forms // Prevent Duplicate Selections
3+ * https :/ / gravitywiz . com /
4+ *
5+ * Prevent duplicate selections in choice - based fields . Currently limited to Checkbox fields with plans
6+ * to support all choice - based fields ( e . g . Radio Buttons , Drop Downs & Multi Selects ) .
7+ *
8+ * For Drop Down field support , use this snippet :
9+ * https :/ / github . com / gravitywiz / snippet - library / blob / master / experimental / gw - prevent - duplicate - drop - down - selections . js
10+ *
11+ * Instructions :
12+ *
13+ * 1. Install this snippet with our free Custom JavaScript plugin .
14+ * https :/ / gravitywiz . com / gravity - forms - custom - javascript /
15+ *
16+ * 2. Add 'gw-prevent-duplicates' to the CSS Class Name setting for any field in which duplicate selections
17+ * should be prevented .
18+ *
19+ $checkboxes = $ ( '.gw-prevent-duplicates' ) . find ( 'input' ) ;
20+
21+ $checkboxes . click ( function ( ) {
22+ gwDisableDuplicates ( $ ( this ) , $checkboxes ) ;
23+ } ) ;
24+
25+ $checkboxes . each ( function ( ) {
26+ gwDisableDuplicates ( $ ( this ) , $checkboxes ) ;
27+ } ) ;
28+
29+ function gwDisableDuplicates ( $elem , $group ) {
30+ let value = $elem . val ( ) ;
31+ $group
32+ . not ( $elem )
33+ . filter ( '[value="{0}"]' . format ( value ) )
34+ . prop ( 'disabled' , $elem . is ( ':checked' ) ) ;
35+ }
You can’t perform that action at this time.
0 commit comments