I have a webform created using interface, and need to hide some fields through button. Using form_alter I have added that button added AJAX call with it. Now I want to remove/hide certain element using that button and AJAX.
Below is the sample code
function xyz_user_signup_form_webform_submission_form1_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
$form['#attached']['library'][] = 'xyz/xyz.global';
$form['start'] = [
'#type' => 'button',
'#ajax' => [
'callback' => 'xyz_user_signup',
],
'#value' => t('START >>'),
];
}
function xyz_user_signup(array &$form, FormStateInterface $form_state) {
$elements = &WebformFormHelper::flattenElements($form['elements']);
$elements['field1']['#access'] = FALSE;
return $elements;
}
On clicking start button I want to hide field1.
Please share your inputs
how about sharing your alter code... otherwise we would have to be psychics.