You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Turbo-Stream, we can want to test it directly:
GET on the path that give us a Turbo-Stram response
Check attributes: action, method
If it's a form, test to submit it
But in tests, methods like submitForm('Save'), selectButton('Save')->form(), should give us the ability to deal with, but the method exclude all fields inside <template>.
In the file src/Symfony/Component/DomCrawler/Form.php (line 421), it exclude all in <template>, by the way, it appear impossible to use the Form methods for testing easily forms inside streams.
How to reproduce
Create a form inside a Turbo-Stream
Call the path that return us that
Possible Solution
Remove the part: [not(ancestor::template)]
Replace it by [( not(ancestor::template) or ancestor::turbo-stream )]
Replace it to respect the order, in test we want to avoid catch of <template> inside a <form>, no <form> inside a <template>: [not(ancestor::template/ancestor::form)]
Additional Context
No response
The text was updated successfully, but these errors were encountered:
mpiot
changed the title
[DomCrawler] [Form] Fields in <template> are excluded
[DomCrawler] [Form] Fields in <template> are excluded (<turbo-stream>)
Feb 7, 2024
This PR was merged into the 6.4 branch.
Discussion
----------
[DomCrawler][Form] Fix the exclusion of <template>
| Q | A
| ------------- | ---
| Branch? | 6.4 <!-- see below -->
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix#53823
| License | MIT
In the DomCrawler, the way to get fields via xPath avoid to find elements inside a `<template>` element:
```html
<form>
<template>
<input type="text" name="not_selected_because_in_template" />
</template>
<input type="text" name="selected_because_out_of_template" />
</form>
```
But, it appear it also exclude form elements if the `<form>` is in a `<template>` (eg: in a `<turbo-stream>`), that bug-fix keep the previous behavior but allow the following:
```html
<turbo-stream>
<template>
<form>
<input type="text" name="selected_because_in_turbo_stream_1" />
<input type="text" name="selected_because_in_turbo_stream_2" />
</form>
</template>
</turbo-stream>
```
As mentioned in #53823, an alternative should be to use `[not(ancestor::template/ancestor::form)]` in the xPath to allow:
```html
<template>
<form>
<input type="text" name="selected_because_parent_is_form_1" />
<input type="text" name="selected_because_parent_is_form_2" />
</form>
</template>
```
Commits
-------
db3a9dd [DomCrawler] [Form] Fix the exclusion of <template>
Symfony version(s) affected
6.4.3
Description
When using Turbo-Stream, we can want to test it directly:
But in tests, methods like
submitForm('Save')
,selectButton('Save')->form()
, should give us the ability to deal with, but the method exclude all fields inside<template>
.In the file
src/Symfony/Component/DomCrawler/Form.php
(line 421), it exclude all in<template>
, by the way, it appear impossible to use theForm
methods for testing easily forms inside streams.How to reproduce
Possible Solution
[not(ancestor::template)]
[( not(ancestor::template) or ancestor::turbo-stream )]
<template>
inside a<form>
, no<form>
inside a<template>
:[not(ancestor::template/ancestor::form)]
Additional Context
No response
The text was updated successfully, but these errors were encountered: