Skip to content
Snippets Groups Projects

Issue #3382802: Disable the 'Remove' button if there is a single row in the allowed values storage setting of the list fields

Closed Issue #3382802: Disable the 'Remove' button if there is a single row in the allowed values storage setting of the list fields
All threads resolved!
Closed Srishti Bankar requested to merge issue/drupal-3382802:3382802-disable-the-remove into 11.x
All threads resolved!
Files
2
@@ -185,6 +185,10 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
'#default_value' => 0,
'#attributes' => ['class' => ['weight']],
];
// Disable the remove button if there is only one row in the table.
if ($max === 0) {
$element['allowed_values']['table'][0]['delete']['#attributes']['disabled'] = 'disabled';
}
if ($delta < count($allowed_values)) {
$query = \Drupal::entityQuery($entity_type_id)
->accessCheck(FALSE)
@@ -261,6 +265,10 @@ public static function addMoreAjax(array $form, FormStateInterface $form_state)
$delta = $element['table']['#max_delta'];
$element['table'][$delta]['item']['#prefix'] = '<div class="ajax-new-content" data-drupal-selector="field-list-add-more-focus-target">' . ($element['table'][$delta]['item']['#prefix'] ?? '');
$element['table'][$delta]['item']['#suffix'] = ($element['table'][$delta]['item']['#suffix'] ?? '') . '</div>';
// Enable the remove button for the first row if there are more rows.
if ($delta > 0 && isset($element['table'][0]['delete']['#attributes']['disabled']) && !isset($element['table'][0]['item']['key']['#attributes']['disabled'])) {
unset($element['table'][0]['delete']['#attributes']['disabled']);
}
$response = new AjaxResponse();
$response->addCommand(new InsertCommand(NULL, $element));
Loading