feat: handle form attribute #7
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes zenstruck/browser#166
Pretty rough implementation of a feature that is central for our project tests, and that we currently circumvent by abusing reflection methods. It would be very nice to have this feature shipped in the library.
I'll let GPT describe the PR :
Description
This pull request refactors the
Form
andElement
classes to improve handling of form elements, particularly those with explicitform
attributes. It updates the logic for identifying a form associated with an element.Refactoring and Enhancements:
src/Dom/Node/Form.php
: Added thefindNodesForForm
method to refine how form-related nodes are identified. This method accounts for both direct descendants and nodes explicitly referencing the form via theform
attribute. Updatedfields
,buttons
, andsubmitButtons
methods to usefindNodesForForm
for improved accuracy.src/Dom/Node/Form/Element.php
: Enhanced theform
method to prioritize elements with explicitform
attributes before falling back to the closestform
ancestor.Test Coverage:
tests/Node/FormTest.php
: Added unit tests to validate the behavior of forms with and without IDs, ensuring correct identification of associated fields and buttons.