I have this code:
$form["noah-search-container"]['actions'] = [
'#type' => 'button',
'#value' => $this->t('Buscar'),
'#ajax' => [
'callback' => '::noahSearchQuery',
],
];
$form["noah-table-container"] = [
"#type" => "container",
"#attributes" => [
"id" => "noah-table-container"
]
];
$form["noah-table-container"]["accession-table"] = [
"#type" => "table",
"#prefix" => "<div id='page_note_ajax_form'>",
"#sufix" => "</div>",
"#header" => [
t("Identificador"),
t("Tipo de material"),
t("Nombre científico"),
t("Banco"),
t("Imagen"),
t("Añadir"),
t("Ficha"),
],
"#attributes" => [
"class" => ["result_message"]
]
];
The button generates the content of the table with this form:
public function noahSearchQuery(array &$form, FormStateInterface $form_state) {
... some stuff...
$form["noah-table-container"]["accession-table"] = NoahIfapaSearchForm::searchTable();
return $form["noah-table-container"]["accession-table"];
}
In the method searchTable
I generate the table in this way:
public static function searchTable() {
$response = [];
... some code...
// $accessions is an array if ID
foreach ($accessions as $accession_id) {
... Some stuff..
// get accession through some API calls,
$response[$accession_id]["identificador"] = [
"#type" => "textfield",
"#title" => t("Identificador"),
'#title_display' => 'invisible',
'#default_value' => $accession[0]
];
$response[$accession_id]["tipo-material"] = [
"#type" => "textfield",
"#title" => t("Tipo de material"),
'#title_display' => 'invisible',
'#default_value' => $accession[1]
];
$response[$accession_id]["nombre-cientf"] = [
"#type" => "textfield",
"#title" => t("Nombre científico"),
"#title_display" => 'invisible',
'#default_value' => $accession[2]
];
$response[$accession_id]["banco"] = [
"#type" => "textfield",
"#title" => t("Banco"),
"#title_display" => 'invisible',
'#default_value' => $accession[3]
];
$response[$accession_id]["img"] = [
"#type" => "textfield",
"#title" => t("Imagen"),
"#title_display" => 'invisible',
'#default_value' => $accession[0]
];
$response[$accession_id]["add"] = [
"#type" => "textfield",
"#title" => t("Añadir"),
"#title_display" => 'invisible',
'#default_value' => $accession[0]
];
$response[$accession_id]["ficha"] = [
"#type" => "textfield",
"#title" => t("Ficha"),
"#title_display" => 'invisible',
'#default_value' => $accession[0]
];
}
return $response;
}
But when I click the button, nothing is printed in the table and there is data to print.