I have a block that has a button, when pressing that button an ajax is triggered that shows a popup with the OpenModalDialogCommand event, after closing the popup I want to deactivate the submit button, does anyone know how to do that?
The form
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Get cupon'),
'#prefix' => '<div id="cupon_form_wrapper">',
'#suffix' => '</div>',
'#attributes' => $results > 0 ? array('disabled' => 'disabled') : [],
'#ajax' => array(
'callback' => '::_modal_form_cupon_ajax_submit',
'event' => 'click'
),
);
function _modal_form_cupon_ajax_submit(array $form, FormStateInterface &$form_state) {
$response = new AjaxResponse();
if ($form_state->getErrors()) {
unset($form['#prefix']);
unset($form['#suffix']);
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -10,
];
$response->addCommand(new HtmlCommand('#cupon_form_wrapper', $form));
}
else {
$content = 'Lorem ipsum';
$title = 'Download';
$response = new AjaxResponse();
$response->addCommand(
new OpenModalDialogCommand(
$title,
$content,
array(
'width'=>'300'
)
),
$form
);
}
return $response;
}