PhpGt/Dom

Implement form property on Element

g105b opened this issue · 3 comments

g105b commented

If an element belongs to a form, it can reference it using the form attribute:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form

Seems that In Firefox "form" property works just for "formable" elements input, select, textarea, button...
For example, SPAN element, even though it is inside the form or has form attribute, returns undefined.

What do you plan, implement it for all elements or..?

g105b commented

It's a good question. I think we should keep the functionality similar to how browsers implement this; a span element should not have a form property, because it is not considered a "form control".

From MDN, elements that are considered form controls are:

  • <button>
  • <fieldset>
  • <input> (with the exception that any whose type is "image" are omitted for historical reasons)
  • <object>
  • <output>
  • <select>
  • <textarea>

However, browsers use an inheritance model that we can't properly emulate in this library, because of the reliance on libxml. See the diagram below:

image

Browsers inheritance goes HTMLInputElement -> HTMLElement -> Element -> Node, meaning that the type of element "HTMLInputElement" can have the trait of "FormControl", but in the PhpGt/Dom library all elements have to be the Element object.

My suggestion is to provide the form property functionality as a live property, but simply return null if the element's tag name is not one of the form control elements above. This will remain compatible to the DOM specification, and will not break any functionality already present within our inheritance model.

g105b commented

Thank you @ognjen-petrovic . I am closing this issue now thanks to your latest contribution.