Closed Bug 228174 Opened 21 years ago Closed 21 years ago

HTMLButtonElement.type should not be readonly to allow creation of differerent buttons with the DOM

Categories

(Core :: DOM: Core & HTML, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla1.7alpha

People

(Reporter: martin.honnen, Assigned: bzbarsky)

Details

Attachments

(3 files, 1 obsolete file)

The DOM Level 2 HTML specification states that the DOM type attribute (or JavaScript property) of the HTMLButtonElement is readonly: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-34812697 However that is somehow nonsense as it means you can create a button dynamically with var button = document.createElement('button'); but that you then cannot change the type of the button to for instance 'reset' or 'button' to create one of the possible HTML button types and insert it into the document. I therefore suggest to make the DOM type attribute/property changeable. If you look back at DOM Level 1 HTML then you will see that the DOM type attribute of HTMLInputElement was specified as readonly too but of while http://www.w3.org/TR/DOM-Level-2-HTML/changes.html states the attribute type is no longer read only The reason for that change was exactly the same problem as outlined above for the HTMLButtonElement, as long as HTMLInputElement.type was readonly you couldn't create the different input element types with the DOM (see http://bugzilla.mozilla.org/show_bug.cgi?id=17544). It would therefore be only consequential to make HTMLButtonElement.type to be readable and writable too. I will attach a test case that demonstrates that currently with Mozilla trying to set HTMLButtonElement.type throws an execption causing any created button to have the default type submit. For completeness: tested with Mozilla 1.6b release build (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031208) but that problems also occurs with earlier versions.
With Mozilla this is a workaround for the problem but I still think HTMLButtonElement.type should not be readonly.
jst, peterv, what do you think? It would be pretty trivial to make this change, I suspect; much easier than input types... Should we push for an erratum to DOM2?
(I'd already made this change in the Web Forms draft, fwiw.)
I'd say let's make this change in Mozilla, but we can't change nsIDOMHTMLButtonElement, it's frozen. We'll need to mark the readonly type attribute in nsIDOMHTMLButtonElement as [noscript] (that change we can make since it doesn't break binary compatibility) and add a writable type attribute to nsIDOMNSHTMLButtonElement, that should do it.
Attached patch So like this? (obsolete) — Splinter Review
Passes the testcase in this bug....
Taking.
Assignee: general → bz-vacation
OS: Windows XP → All
Priority: -- → P2
Hardware: PC → All
Target Milestone: --- → mozilla1.7alpha
Comment on attachment 138461 [details] [diff] [review] So like this? jst, would you review?
Attachment #138461 - Flags: superreview?(jst)
Attachment #138461 - Flags: review?(jst)
Comment on attachment 138461 [details] [diff] [review] So like this? Yeah, found a few nits to pick... - In dom/public/idl/html/nsIDOMHTMLButtonElement.idl: - readonly attribute DOMString type; + [noscript] readonly attribute DOMString type; Add a comment saying that there's a scriptable type attribute in nsIDOMNSHTMLButtonElement. - In dom/public/idl/html/nsIDOMNSHTMLButtonElement.idl: + attribute DOMString type; Loose the extra space after 'attribute'. r+sr=jst
Attachment #138461 - Flags: superreview?(jst)
Attachment #138461 - Flags: superreview+
Attachment #138461 - Flags: review?(jst)
Attachment #138461 - Flags: review+
Attached patch With nits fixedSplinter Review
Attachment #138461 - Attachment is obsolete: true
Checked in for 1.7a. Martin, thanks for bringing this up!
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: