Skip to content

Commit d6594b7

Browse files
committed
gpro-enable-when-dynamically-populated.php: Updated to choice-based fields as readonly when the dynamically populated value matches an existing choice.
1 parent afe5c0b commit d6594b7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

gp-read-only/gpro-enable-when-dynamically-populated.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,28 @@
1212

1313
foreach ( $form['fields'] as &$field ) {
1414

15-
if ( $field->gwreadonly_enable ) {
15+
if ( ! $field->gwreadonly_enable ) {
16+
continue;
17+
}
1618

17-
$value = GFFormsModel::get_field_value( $field, $field_values, false ) || $field->gppa_hydrated_value;
18-
$has_matching_choice = false;
19+
$value = GFFormsModel::get_field_value( $field, $field_values, false ) || $field->gppa_hydrated_value;
1920

20-
// If we have a value and we're populating a choice-based field, make sure the value matches a choice.
21-
if ( $value && ! empty( $field->choices ) ) {
22-
foreach ( $field->choices as $choice ) {
23-
if ( $choice['value'] == $value ) {
24-
$has_matching_choice = true;
25-
break;
26-
}
21+
// If we have a value and we're populating a choice-based field, make sure the value matches a choice.
22+
if ( $value && ! empty( $field->choices ) ) {
23+
$has_matching_choice = false;
24+
foreach ( $field->choices as $choice ) {
25+
if ( $choice['value'] == $value ) {
26+
$has_matching_choice = true;
27+
break;
2728
}
2829
}
2930

30-
if ( ! $value || ! $has_matching_choice ) {
31-
$field->gwreadonly_enable = false;
32-
}
31+
}
3332

33+
if ( ! $value || ( isset( $has_matching_choice ) && ! $has_matching_choice ) ) {
34+
$field->gwreadonly_enable = false;
3435
}
36+
3537
}
3638

3739
return $form;

0 commit comments

Comments
 (0)