Skip to content

Commit 0c0bbb4

Browse files
authored
gfcs-auto-chained-select.php: Migrating from experimental folder. (#929)
1 parent d1f7e05 commit 0c0bbb4

File tree

1 file changed

+24
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)