Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions experimental/gfcs-auto-chained-select.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
<?php
/**
* Gravity Wiz // Gravity Forms Chained Selects // Auto Select Only Option
* https://gravitywiz.com/
*
* The Gravity Forms Chained Selects field requires you to manually select a value in each Drop Down
* even if there is only a single option available in that Drop Down. This snippet will automatically
* selected an option when it is the only option available.
* We're no longer using the experimental folder for experimental snippets. 🚧
* You can now find the snippet here:
* https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gfcs-auto-chained-select.php.php
*/
add_filter( 'gform_chained_selects_input_choices', function( $choices ) {
$choices = gfcs_auto_select_only_choice( $choices );
return $choices;
} );

function gfcs_auto_select_only_choice( $choices ) {

$choices[0]['isSelected'] = $choices[0]['isSelected'] || count( $choices ) <= 1;

if ( ! empty( $choices['choices'] ) ) {
$choices['choices'] = gfcs_auto_select_only_choice( $choices['choices'] );
}

return $choices;
}
Loading