Skip to content

[DomCrawler] Add something to select non-existing value in ChoiceFormField #60435

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
tjveldhuizen opened this issue May 16, 2025 · 0 comments

Comments

@tjveldhuizen
Copy link
Contributor

Description

When using DomCrawler in a test case, one is able to set the value of a Choice form field using the setValue()method, The implementation of this method checks if the value to be set matches one of the <option> elements for the specific <select>. When the <select> is populated via Javascript (using select2 or tom-select for example), those <option> elements are not available during the test.

Since the \Symfony\Component\DomCrawler\Field\ChoiceFormField::disableValidation method is internal, I should not use it in my test. Would it be better to add this method to the API, or to add a flag to the setValue() method which disables the 'is the option available' check?

Example

// Ajax populated field using internal 'disableValidation'
$personField= $form['create[person]'];
self::assertInstanceOf(ChoiceFormField::class, $personField);
$personField->disableValidation()->setValue('CMD1A1A');

// Regular <select>
$nationalityVeld = $form['create[nationality]'];
self::assertInstanceOf(ChoiceFormField::class, $nationalityVeld);
$nationalityVeld->setValue('NED');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants