Skip to content
Snippets Groups Projects
Verified Commit f78cb110 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3396887 by lauriii, tim.plunkett: Once is reset for ajax dialog buttons...

Issue #3396887 by lauriii, tim.plunkett: Once is reset for ajax dialog buttons when dialog is opened

(cherry picked from commit 9766f13f)
parent c7541f1f
No related branches found
No related tags found
20 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump,!5950Issue #3403653 by alexpott, longwave: Incorporate improvements to how contrib runs PHPStan to core,!5858Issue #3401971 by fjgarlin: Test-only job shouldn't require constant rebases...,!5716Draft: Issue #3401102 by Spokje, longwave, smustgrave: Nightwatch artifacts on GitLab not retained,!5674Transaction autocommit during shutdown relies on unreliable object destruction order,!5644Issue #3395563 by nireneko, marvil07, lauriii, borisson_, smustgrave, Wim...
Pipeline #40477 canceled
Pipeline: drupal

#40486

    Pipeline: drupal

    #40485

      Pipeline: drupal

      #40484

        +1
        ......@@ -94,6 +94,7 @@
        buttons.push({
        text: $originalButton.html() || $originalButton.attr('value'),
        class: $originalButton.attr('class'),
        'data-once': $originalButton.data('once'),
        click(e) {
        // If the original button is an anchor tag, triggering the "click"
        // event will not simulate a click. Use the click method instead.
        ......@@ -104,8 +105,8 @@
        .trigger('mousedown')
        .trigger('mouseup')
        .trigger('click');
        e.preventDefault();
        }
        e.preventDefault();
        },
        });
        });
        ......
        ......@@ -2,6 +2,8 @@
        namespace Drupal\ajax_test\Form;
        use Drupal\Core\Ajax\AjaxResponse;
        use Drupal\Core\Ajax\MessageCommand;
        use Drupal\Core\Url;
        use Drupal\Core\Form\FormBase;
        use Drupal\Core\Form\FormStateInterface;
        ......@@ -39,26 +41,44 @@ public function buildForm(array $form, FormStateInterface $form_state) {
        '#value' => $this->t('Do it'),
        ];
        $form['actions']['preview'] = [
        '#title' => 'Preview',
        '#type' => 'link',
        '#url' => Url::fromRoute('ajax_test.dialog_form'),
        '#attributes' => [
        'class' => ['use-ajax', 'button'],
        'data-dialog-type' => 'modal',
        ],
        ];
        $form['actions']['hello_world'] = [
        '#type' => 'submit',
        '#value' => $this->t('Preview'),
        '#value' => $this->t('Hello world'),
        // No regular submit-handler. This form only works via JavaScript.
        '#submit' => [],
        '#ajax' => [
        // This means the ::preview() method on this class would be invoked in
        // case of a click event. However, since Drupal core's test runner only
        // is able to execute PHP, not JS, there is no point in actually
        // implementing this method, because we can never let it be called from
        // JS; we'd have to manually call it from PHP, at which point we would
        // not actually be testing it.
        // Therefore we consciously choose to not implement this method, because
        // we cannot meaningfully test it anyway.
        'callback' => '::preview',
        'callback' => '::helloWorld',
        'event' => 'click',
        ],
        ];
        return $form;
        }
        /**
        * An AJAX callback that prints "Hello World!" as a message.
        *
        * @param array $form
        * The form array to remove elements from.
        * @param \Drupal\Core\Form\FormStateInterface $form_state
        * The current state of the form.
        *
        * @return \Drupal\Core\Ajax\AjaxResponse
        * An AJAX response.
        */
        public function helloWorld(array &$form, FormStateInterface $form_state) {
        $response = new AjaxResponse();
        $response->addCommand(new MessageCommand('Hello world!'));
        return $response;
        }
        /**
        * {@inheritdoc}
        */
        ......
        ......@@ -145,26 +145,32 @@ public function testDialog() {
        $preview = $form_dialog->findButton('Preview');
        $this->assertNotNull($preview, 'The dialog contains a "Preview" button.');
        // When a form with submit inputs is in a dialog, the form's submit inputs
        // are copied to the dialog buttonpane as buttons. The originals should have
        // their styles set to display: none.
        $hidden_buttons = $this->getSession()->getPage()->findAll('css', '.ajax-test-form [type="submit"]');
        $this->assertCount(2, $hidden_buttons);
        // Form submit inputs, link buttons, and buttons in dialog are copied to the
        // dialog buttonpane as buttons. The originals should have their styles set
        // to display: none.
        $hidden_buttons = $this->getSession()->getPage()->findAll('css', '.ajax-test-form .button');
        $this->assertCount(3, $hidden_buttons);
        $hidden_button_text = [];
        foreach ($hidden_buttons as $button) {
        $styles = $button->getAttribute('style');
        $this->assertStringContainsStringIgnoringCase('display: none;', $styles);
        $hidden_button_text[] = $button->getAttribute('value');
        $hidden_button_text[] = $button->hasAttribute('value') ? $button->getAttribute('value') : $button->getHtml();
        }
        // The copied buttons should have the same text as the submit inputs they
        // were copied from.
        $moved_to_buttonpane_buttons = $this->getSession()->getPage()->findAll('css', '.ui-dialog-buttonpane button');
        $this->assertCount(2, $moved_to_buttonpane_buttons);
        $this->assertCount(3, $moved_to_buttonpane_buttons);
        foreach ($moved_to_buttonpane_buttons as $key => $button) {
        $this->assertEquals($hidden_button_text[$key], $button->getText());
        }
        // Press buttons in the dialog to ensure there are no AJAX errors.
        $this->assertSession()->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Hello world');
        $this->assertSession()->assertWaitOnAjaxRequest();
        $this->assertSession()->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Preview');
        $this->assertSession()->assertWaitOnAjaxRequest();
        // Reset: close the form.
        $form_dialog->findButton('Close')->press();
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment