Opened 12 years ago

Closed 12 years ago

#10616 closed defect (wontfix)

formToJson skips elements that have only an id

Reported by: Simon Speich Owned by: anonymous
Priority: high Milestone: tbd
Component: Core Version: 1.4.0
Keywords: Cc:
Blocked By: Blocking:


The methods dojo.formToJson(), dojo.formToQuery() and dojo.formToObject() skip HTMLFormElements that have only an id attribute, but not a name attribute. I think it should work for both (if this is a 'feature' then it should be at least be mentioned in the docs).

I setup a testcase at

Change History (3)

comment:1 Changed 12 years ago by James Burke

I have not done the proper work to investigate this, but here is a thought. It may be this stems from formToQuery, which tries to simulate what will happen if a form is submitted, what the submission string would look like. In that case, for regular form submissions are only elements with name values sent to the server?

That is my initial guess at explaining the behavior, but more research needs to be done. If you want to confirm that doing a regular form submit either does or does not send element values for elements with just ID and not name, that would be good (noting the browsers used to test too).

comment:2 Changed 12 years ago by Simon Speich

Ok, I see your point with formToQuery. It is the case that only form elements with a name attribute are posted to the server. And it is actually sort of mentioned in the docs

<<This particular function takes a HTML form node and converts the form elements into a JavaScript? object of name/value pairs. Disabled form elements, buttons, and other non-valued HTML elements are skipped.>>

But maybe that could be made a little clearer by adding: <<Note that elements with only an id attribute are ignored.>>

But anyway, as a user of the toolkit I would expect these methods to operate on the id attribute as well. So this is not a bug, but a feature request.

comment:3 Changed 12 years ago by James Burke

Resolution: wontfix
Status: newclosed

I updated the docs to call out that elements with ids but no names are skipped, but keeping the behavior to match form submissions from HTML.

Note: See TracTickets for help on using tickets.