Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot include two pattern select elements on same page #316

Open
nedjo opened this issue Dec 8, 2020 · 0 comments · May be fixed by #317
Open

Cannot include two pattern select elements on same page #316

nedjo opened this issue Dec 8, 2020 · 0 comments · May be fixed by #317

Comments

@nedjo
Copy link

nedjo commented Dec 8, 2020

Bug description

In Drupal\ui_patterns\Form\PatternDisplayFormTrait::buildPatternDisplayForm() we explicitly assign an 'id' attribute to the $form['pattern'] select element as follows:

      '#attributes' => ['id' => 'patterns-select'],

and subsequently attach #states behaviours using this same hard-coded 'patterns-select' ID:

          '#states' => [
            'visible' => [
              'select[id="patterns-select"]' => ['value' => $pattern_id],
            ],
          ],

This means placing more than one pattern select on a given form leads to invalid HTML and broken #states.

Use case

An example use case is in the UI Patterns Blocks module, see the issue Support sub-patterns for block .

Proposed fix

Use Html::getUniqueId() to generate a unique ID value and use that in the '#states' values.

nedjo pushed a commit to nedjo/ui_patterns that referenced this issue Dec 8, 2020
@nedjo nedjo changed the title Cannot include two pattern select elements on same page Cannot include two pattern select elements in same form Dec 8, 2020
@nedjo nedjo changed the title Cannot include two pattern select elements in same form Cannot include two pattern select elements on same page Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant