Skip to content
Snippets Groups Projects
Verified Commit 716a1028 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3076054 by godotislate, joaopauloc.dev, smustgrave, nod_, nayana_mvr,...

Issue #3076054 by godotislate, joaopauloc.dev, smustgrave, nod_, nayana_mvr, larowlan, alexpott, lauriii, quietone, benjifisher, anup.singh, bnjmnm: Existing field items should not be validated when adding another item in widget for unlimited cardinality field
parent cdf03eab
No related branches found
No related tags found
26 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #86367 passed with warnings
Pipeline: drupal

#86390

    Pipeline: drupal

    #86380

      Pipeline: drupal

      #86368

        ......@@ -5,6 +5,9 @@
        use Drupal\Component\Utility\Html;
        use Drupal\Component\Utility\NestedArray;
        use Drupal\Component\Utility\SortArray;
        use Drupal\Core\Ajax\AjaxResponse;
        use Drupal\Core\Ajax\FocusFirstCommand;
        use Drupal\Core\Ajax\InsertCommand;
        use Drupal\Core\Form\FormStateInterface;
        use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
        use Drupal\Core\Render\Element;
        ......@@ -280,7 +283,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
        '#name' => strtr($id_prefix, '-', '_') . '_add_more',
        '#value' => t('Add another item'),
        '#attributes' => ['class' => ['field-add-more-submit']],
        '#limit_validation_errors' => [array_merge($parents, [$field_name])],
        '#limit_validation_errors' => [],
        '#submit' => [[static::class, 'addMoreSubmit']],
        '#ajax' => [
        'callback' => [static::class, 'addMoreAjax'],
        ......@@ -349,10 +352,18 @@ public static function addMoreAjax(array $form, FormStateInterface $form_state)
        // Add a DIV around the delta receiving the Ajax effect.
        $delta = $element['#max_delta'];
        $element[$delta]['#prefix'] = '<div class="ajax-new-content">' . ($element[$delta]['#prefix'] ?? '');
        // Construct an attribute to add to div for use as selector to set the focus on.
        $button_parent = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1));
        $focus_attribute = 'data-drupal-selector="field-' . $button_parent['#field_name'] . '-more-focus-target"';
        $element[$delta]['#prefix'] = '<div class="ajax-new-content" ' . $focus_attribute . '>' . ($element[$delta]['#prefix'] ?? '');
        $element[$delta]['#suffix'] = ($element[$delta]['#suffix'] ?? '') . '</div>';
        return $element;
        // Turn render array into response with AJAX commands.
        $response = new AjaxResponse();
        $response->addCommand(new InsertCommand(NULL, $element));
        // Add command to set the focus on first focusable element within the div.
        $response->addCommand(new FocusFirstCommand("[$focus_attribute]"));
        return $response;
        }
        /**
        ......
        ......@@ -169,4 +169,45 @@ public function testFieldMultipleValueWidget() {
        $this->assertSame('', $field_1->getValue());
        }
        /**
        * Tests that no validation occurs on field on "Add more" click.
        */
        public function testFieldMultipleValueWidgetAddMoreNoValidation() {
        // Set unlimited field to be required.
        $field_name = 'field_unlimited';
        $field = FieldConfig::loadByName('entity_test', 'entity_test', $field_name);
        $field->setRequired(TRUE);
        $field->save();
        $this->drupalGet('entity_test/add');
        $assert_session = $this->assertSession();
        $page = $this->getSession()->getPage();
        // Add another item with the first item being empty, even though the field
        // is required.
        $add_more_button = $page->findButton('field_unlimited_add_more');
        $add_more_button->click();
        $field_1 = $assert_session->waitForField('field_unlimited[1][value]');
        $this->assertNotEmpty($field_1, 'Successfully added another item.');
        // Confirm the new item has focus.
        $this->assertHasFocusByAttribute('name', 'field_unlimited[1][value]');
        // The first item should not be in error state.
        $assert_session->elementNotExists('css', 'input[name="field_unlimited[0][value]"].error');
        }
        /**
        * Asserts an element specified by an attribute value has focus.
        *
        * @param string $name
        * The attribute name.
        * @param string $value
        * The attribute value.
        *
        * @todo Replace with assertHasFocus() in https://drupal.org/i/3041768.
        */
        private function assertHasFocusByAttribute(string $name, string $value): void {
        $active_element = $this->getSession()->evaluateScript('document.activeElement');
        $this->assertSame($value, $active_element->attribute($name));
        }
        }
        ......@@ -151,14 +151,14 @@ public function testFieldWidgetsWithLimitedValidationErrors() {
        $assert_session->elementExists('css', 'input#edit-test-file-0-remove-button');
        // Make the 'Test multiple' field required and check that adding another
        // item throws a validation error.
        // item does not throw a validation error.
        $field_config = FieldConfig::loadByName($this->entityTypeId, $this->entityTypeId, $this->fieldNameMultiple);
        $field_config->setRequired(TRUE);
        $field_config->save();
        $this->drupalGet($this->entityTypeId . '/add');
        $this->submitForm([], 'Add another item');
        $assert_session->pageTextContains('Test multiple (value 1) field is required.');
        $assert_session->pageTextNotContains('Test multiple (value 1) field is required.');
        // Check that saving the form without entering any value for the required
        // field still throws the proper validation errors.
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment