File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Gravity Wiz // Gravity Forms Chained Selects // Auto Select Only Option
4+ * https://gravitywiz.com/
5+ *
6+ * The Gravity Forms Chained Selects field requires you to manually select a value in each Drop Down
7+ * even if there is only a single option available in that Drop Down. This snippet will automatically
8+ * selected an option when it is the only option available.
9+ */
10+ add_filter ( 'gform_chained_selects_input_choices ' , function ( $ choices ) {
11+ $ choices = gfcs_auto_select_only_choice ( $ choices );
12+ return $ choices ;
13+ } );
14+
15+ function gfcs_auto_select_only_choice ( $ choices ) {
16+
17+ $ choices [0 ]['isSelected ' ] = $ choices [0 ]['isSelected ' ] || count ( $ choices ) <= 1 ;
18+
19+ if ( ! empty ( $ choices ['choices ' ] ) ) {
20+ $ choices ['choices ' ] = gfcs_auto_select_only_choice ( $ choices ['choices ' ] );
21+ }
22+
23+ return $ choices ;
24+ }
You can’t perform that action at this time.
0 commit comments