2 added 1 character in body
source | link

Thanks to @Clive for pointing me in the right direction.

I've managed to accomplish what I want with the following changes to the form_alter function:

$form['field_type_app_details']['widget']['#ajax'] = array(
  'callback' => 'ajax_type_callback',
  'event' => 'change',
  'wrapper' => 'version-release'
);
$form['field_version']['#prefix'] = '<div id="version-release">';
$form['field_version']['#suffix'] = '</div>';
$typeValueChangedByUser = $form_state->getValue(['field_type_app_details', 0, 'value']);
$typeToCheck = $typeValueChangedByUser ? $typeValueChangedByUser : $form['field_type_app_details']['widget']['#default_value'][0];
if (typeToCheck$typeToCheck  === 'First') {
  unset($form['field_version']['#disabled']);
  $form['field_version']['widget'][0]['value']['#required'] = true;
} else {
  $form['field_version']['#disabled'] = 'disabled';
  $form['field_version']['widget'][0]['value']['#required'] = false;
}

And the following change to the ajax_callback function:

function ajax_type_callback($form, $form_state) {
  return $form['field_version'];
}

Thanks to @Clive for pointing me in the right direction.

I've managed to accomplish what I want with the following changes to the form_alter function:

$form['field_type_app_details']['widget']['#ajax'] = array(
  'callback' => 'ajax_type_callback',
  'event' => 'change',
  'wrapper' => 'version-release'
);
$form['field_version']['#prefix'] = '<div id="version-release">';
$form['field_version']['#suffix'] = '</div>';
$typeValueChangedByUser = $form_state->getValue(['field_type_app_details', 0, 'value']);
$typeToCheck = $typeValueChangedByUser ? $typeValueChangedByUser : $form['field_type_app_details']['widget']['#default_value'][0];
if (typeToCheck  === 'First') {
  unset($form['field_version']['#disabled']);
  $form['field_version']['widget'][0]['value']['#required'] = true;
} else {
  $form['field_version']['#disabled'] = 'disabled';
  $form['field_version']['widget'][0]['value']['#required'] = false;
}

And the following change to the ajax_callback function:

function ajax_type_callback($form, $form_state) {
  return $form['field_version'];
}

Thanks to @Clive for pointing me in the right direction.

I've managed to accomplish what I want with the following changes to the form_alter function:

$form['field_type_app_details']['widget']['#ajax'] = array(
  'callback' => 'ajax_type_callback',
  'event' => 'change',
  'wrapper' => 'version-release'
);
$form['field_version']['#prefix'] = '<div id="version-release">';
$form['field_version']['#suffix'] = '</div>';
$typeValueChangedByUser = $form_state->getValue(['field_type_app_details', 0, 'value']);
$typeToCheck = $typeValueChangedByUser ? $typeValueChangedByUser : $form['field_type_app_details']['widget']['#default_value'][0];
if ($typeToCheck  === 'First') {
  unset($form['field_version']['#disabled']);
  $form['field_version']['widget'][0]['value']['#required'] = true;
} else {
  $form['field_version']['#disabled'] = 'disabled';
  $form['field_version']['widget'][0]['value']['#required'] = false;
}

And the following change to the ajax_callback function:

function ajax_type_callback($form, $form_state) {
  return $form['field_version'];
}
1
source | link

Thanks to @Clive for pointing me in the right direction.

I've managed to accomplish what I want with the following changes to the form_alter function:

$form['field_type_app_details']['widget']['#ajax'] = array(
  'callback' => 'ajax_type_callback',
  'event' => 'change',
  'wrapper' => 'version-release'
);
$form['field_version']['#prefix'] = '<div id="version-release">';
$form['field_version']['#suffix'] = '</div>';
$typeValueChangedByUser = $form_state->getValue(['field_type_app_details', 0, 'value']);
$typeToCheck = $typeValueChangedByUser ? $typeValueChangedByUser : $form['field_type_app_details']['widget']['#default_value'][0];
if (typeToCheck  === 'First') {
  unset($form['field_version']['#disabled']);
  $form['field_version']['widget'][0]['value']['#required'] = true;
} else {
  $form['field_version']['#disabled'] = 'disabled';
  $form['field_version']['widget'][0]['value']['#required'] = false;
}

And the following change to the ajax_callback function:

function ajax_type_callback($form, $form_state) {
  return $form['field_version'];
}