Skip to content

Navigation Menu

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

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
Loading
from

Conversation

norkunas
Copy link
Contributor

@norkunas norkunas commented Jan 17, 2024

Q A
Branch? 7.1
Bug fix? no (but would say yes)
New feature? yes
Deprecations? no
Issues symfony/ux#1334 (comment) symfony/ux#1334 (comment) #47642
License MIT

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 🙏

@carsonbot carsonbot added this to the 7.1 milestone Jan 17, 2024
@carsonbot carsonbot changed the title [DOMCrawler] Allow to add choices to single select [DomCrawler] Allow to add choices to single select Jan 17, 2024
@norkunas norkunas force-pushed the domcrawler-single-select-addchoice branch from fa4c796 to a23a708 Compare January 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

stof commented Jan 17, 2024

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

@norkunas
Copy link
Contributor Author

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
Contributor Author

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 ?

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.