I am trying to set the value of a drop-down list when a form is rendered. This is on the first page of the form. I’ve set up tests to be logged and the isSelected value is correctly changed to 1 for the option in question but when I look at the form on screen, the drop-down in question has not updated to show the correct choice. Here’s the code in question:
//$orgCode is determined in by earlier code and should match one of the values in the dropdown list.
foreach( $form['fields'] as &$field ) {
if($field->id == 11) {
$options = $field["choices"];
foreach ( $options as $fkey => $option ) {
if($option['value'] == $orgCode){
GFCommon::log_debug("val1-" . $option['value']);
// --> Logged data: "val1-uri" - we have found the correct option
GFCommon::log_debug("val2-" . $option['isSelected']);
//--> Logged data: "val2-" - not selected
$option['isSelected'] = true; // --> THE KEY LINE
GFCommon::log_debug("val3-" . $option['isSelected']);
// --> Logged data: "val3-1" - isSelected has apparently been set
}
}
}
}