Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DomCrawler] Attach label to form fields#18322
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| * | ||
| * @return \DOMNode|null The \DOMElement of the associated label tag or null if none was found | ||
| */ | ||
| privatefunctionfindAssociatedLabel(\DOMElement$node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Have you considered moving this implementation to the FormField'sgetLabel() method? You wouldn't have to add a new argument to FormField's constructor, and the logic wouldn't be called if the label wasn't accessed.ownerDocument property is available on the$node that's already passed to the FormField.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
That's a good point. I'll refactor it.
efd3577 to93f8d8fComparecarlosV2 commentedApr 7, 2016
Sorry@stof, I realised while you where commenting it. It should be fixed now. |
| if ($labels->length >0) { | ||
| return$labels->item(0); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think the id-based logic should have higher priority
xabbuh commentedApr 11, 2016
What about something like this: <form><div><labelfor="my_field">Input the result of 3 + 4:</label></div><div><inputtype="text"id="my_field"name="my_field"/></div></form> |
carlosV2 commentedApr 11, 2016
@xabbuh it will work as far as the label is within the form node computed by the crawler. In this case, parenting would fail but the label will still be found by the If it is suitable, I can add a new test to prove this although it seems to be working on my local. |
xabbuh commentedApr 11, 2016
@carlosV2 You are right. I misread the way the XPath object is created. |
fabpot commentedJun 14, 2016
Thank you@carlosV2. |
While building a software to extract information from a webpage, I need to fill a form with hints on the fields labels.
Example:
I thought it would be handy to have the field labels attached to each field.
So given the previous form you could now do: