Have a simple form including few of the input elements that should show up the data (based on the input) on tableselect (part of the same form) through the ajax callback functionality.
//submit button
$form['action'] = [
'#type' => 'button',
'#value' => $this->t('Submit'),
'#ajax' => [
'callback' => '::setMessage',
'prevent' => 'click',
'wrapper' => 'scrollable',
'method' => 'replace',
'effect' => 'fade',
],
'#suffix' => '</div></div>',
];
and within my ajax callback function:
public function setMessage(array $form, FormStateInterface $form_state) {
$options = array();
$header = [
'subject_id' => t('Subject ID'),
'ct_availability' => t('CT Availability'),
'sex' => t('Sex'),
'race' => t('Race'),
'cardiovascular_disease' => t('Cardiovascular Disease'),
'registration_age' => t('Registration_Age'),
];
$options = $this->getOptions(); //getting the associative array
dpm($options); //printing to make sure that the array is filled
//assigning to the table
$form['table']['#header'] = $header;
$form['table']['#options'] = $options;
return $form['table'];
}
The header gets assigned fine and the table is displayed only with it. The data doesn't get filled and it seems the #options does not get assigned to the tableselect thus showing no data.
There are no ajax errors from the console
Wondering if it has something to do with 'processTableselect' function or rebuilding the form before returning the table element?
Or if it is a wrong approach to assign form element attributes within the callback function?