A. Pérez A. Pérez - 19 days ago 8
YAML Question

Drupal 8 YAML Form Module: How do I change the value of a Hidden element?

A few days ago I asked a question about Drupal 8 YAML Form Module: Populate Select Element. I found a solution that it works fine for me.

But now I've got a new doubt. I would like to change the value of a Hidden element and depending of this value, to show some elements in the form or not. I'm trying to implement the hook

hook_yamlform_element_info_alter(array &$elements)
and I do
$elements['hidden_element_name']['#value'] = 'New value of the hidden element'
but it doesn't work.

Any ideas? Thanks in advance!

Answer

Here is the solution: How do I change the value of a Hidden element?

Basically, I've implemented hook_form_FORM_ID_alter() and I do:

$form['elements']['hidden_element_name']['#value'] = 'New value of the hidden element';

I hope it helps someone!

Comments