Skip to content

Commit cd558da

Browse files
authored
gpcc-copy-to-conditionally-hidden-fields.php: Fixed an issue with copying value with multi input field triggers.
1 parent b592f7d commit cd558da

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

gp-copy-cat/gpcc-copy-to-conditionally-hidden-fields.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,23 @@
2929
continue;
3030
}
3131

32-
$source_field = GFAPI::get_field( $form, $target['source'] );
33-
$source_values = $source_field->get_value_submission( array() );
32+
$source_field = GFAPI::get_field( $form, $target['source'] );
33+
$source_values = $source_field->get_value_submission( array() );
34+
$condition_field = GFAPI::get_field( $form, $target['condition'] );
35+
$condition_value = $condition_field->get_value_submission( $entry );
36+
37+
// for multi-input fields, we need to check the index
38+
// to see if the condition is met.
39+
if ( strpos( $target['condition'], '.' ) !== false ) {
40+
list( $base, $index ) = explode( '.', $target['condition'] );
41+
if ( isset( $condition_field['choices'][ (int) $index ] ) ) {
42+
if ( $condition_field['choices'][ (int) $index ]['value'] !== $condition_value ) {
43+
continue;
44+
}
45+
} else {
46+
continue;
47+
}
48+
}
3449

3550
if ( is_array( $source_values ) ) {
3651
foreach ( $source_values as $input_id => $source_value ) {

0 commit comments

Comments
 (0)