File tree Expand file tree Collapse file tree 1 file changed +2
-27
lines changed
Expand file tree Collapse file tree 1 file changed +2
-27
lines changed Original file line number Diff line number Diff line change 11/**
2- * Gravity Wiz // Gravity Forms // Limit Multi Selects
3- * https://gravitywiz.com/
4- *
5- * Limit how many options may be selected in a Multi Select field. Works with
6- * regular Multi Select fields as well as fields with Enhanced UI enabled.
7- *
8- * Instructions:
9- *
10- * 1. Install this snippet with our free Custom JavaScript plugin.
11- * https://gravitywiz.com/gravity-forms-custom-javascript/
12- * 2. Configure snippet per inline instructions.
2+ * This snippet has graduated from the experimental folder 🎓
3+ * You can now find the snippet here: https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-limit-multiselect.js
134 */
14- // Update "1" to the ID of your Multi Select field.
15- $ ( '#input_GFFORMID_1' ) . on ( 'change' , function ( ) {
16- // Update "2" to the max number of options that should be selectable.
17- var maxSelected = 2 ;
18- // Alternate: Set max number by the value of another field.
19- // var maxSelected = parseInt( $( '#input_GFFORMID_4' ).val() );
20- limitMultiSelect ( $ ( this ) , maxSelected ) ;
21- } ) ;
22-
23- function limitMultiSelect ( $select , maxSelected ) {
24- var disable = $select . find ( 'option:checked' ) . length === maxSelected ;
25- $select
26- . find ( 'option:not(:checked)' )
27- . prop ( 'disabled' , disable )
28- . trigger ( 'chosen:updated' ) ;
29- }
You can’t perform that action at this time.
0 commit comments