Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DomCrawler] Allow to add choices to single select#53559

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
norkunas wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromnorkunas:domcrawler-single-select-addchoice

Conversation

norkunas
Copy link
Contributor

@norkunasnorkunas commentedJan 17, 2024
edited
Loading

QA
Branch?7.1
Bug fix?no (but would say yes)
New feature?yes
Deprecations?no
Issuessymfony/ux#1334 (comment)symfony/ux#1334 (comment)#47642
LicenseMIT

Not sure why this was designed this way, but when using JS autocomplete's we cannot simulate it's behavior with a select element when a new choice was added to the list

cc@yceruto 🙏

bernard-ng reacted with thumbs up emoji
@carsonbotcarsonbot added this to the7.1 milestoneJan 17, 2024
@carsonbotcarsonbot changed the title[DOMCrawler] Allow to add choices to single select[DomCrawler] Allow to add choices to single selectJan 17, 2024
@norkunasnorkunasforce-pushed thedomcrawler-single-select-addchoice branch fromfa4c796 toa23a708CompareJanuary 17, 2024 10:21
@@ -110,6 +110,18 @@ public function testSelects()
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true, '->setValue() throws an \InvalidArgumentException if the value is an array');
}

$option = $this->createNode('option', 'Hello World', ['value' => 'hello_world']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please create a separate test instead of adding more things in the same test. This provides a much better experience:

  • we have a test name telling us what this is about
  • the status of the test is separate, giving us better failures

Existing dom-crawler tests are not following the testing best practices because this is one of the oldest components of Symfony, at a time where the usage of phpunit in Symfony was still quite new.

@stof
Copy link
Member

As this method is@internal, I don't think it is the solution to the use case anyway.

@norkunas
Copy link
ContributorAuthor

As this method is@internal, I don't think it is the solution to the use case anyway.

What would you suggest then? Can we remove@internal to allow people simulate this behavior?

@@ -143,14 +143,14 @@ public function setValue(string|array|bool|null $value): void
*/
public function addChoice(\DOMElement $node): void
{
if (!$this->multiple && 'radio' !== $this->type) {
if (!$this->multiple &&('radio' !== $this->type && 'select' !== $this->type)) {
throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Message (and method docblock) should be updated.

@stof Would that be a BC break, as select were refused before ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@smnandre given that's an@internal method BC break does not apply here

throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
}

$option = $this->buildOptionValue($node);
$this->options[] = $option;

if ($node->hasAttribute('checked')) {
if ($node->hasAttribute('checked') || $node->hasAttribute('selected')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

type === "radio" a&& attribute checked || type === select && attribute selected ?

@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stofstofstof left review comments

@smnandresmnandresmnandre left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@norkunas@stof@smnandre@fabpot@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp