I have checkboxes that do not exist until users perform various actions via ajax.(in a modal form)
The items are simple checkboxes like the one below:
$form['product_information']['variation'][$variation_id]['enabled'] = [
'#type' => 'checkbox',
'#title' => t('Track Stock'),
'#default_value' => TRUE,
];
My ajax callback looks like this:
function product_information_form_get_element(&$form, FormStateInterface $form_state) {
return $form['product_information'];
}
Now, when the form first runs, that checkbox does not exist. Only after users perform certain actions does the checkbox exist. (This is an altered form, and the checkbox is conditionally added in form_alter)
While I expected the checkbox to be checked when created, since the default_value is TRUE, it is not. The Form State values and User Input both somehow get populate with "0" and "NULL" respectively.
Is this intentional behavior? If so, is there a way around it? The strange thing is - it only seems to affect checkboxes. It seemed to work fine with a textfield that had a default value.
To reproduce, have a checkbox that is hidden by default and conditionally shown based off an ajax callback from a modal form
Closed: duplicate
9.5
Last updated
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.