Re: Submitting forms as JSON

That's a giant paragraph, but I think it boils down to:

> we really should be adding new capabilities to the platform in an
EWM-friendly way from here-on out.

Straw-man proposal example:

form.serialize = function(elements) {
  let json = {};
  for el of elements {
    json[el.name] = el.serialize();
  }
  return { body: JSON.stringify(json), contentType: "application/json" }
}

In this example, body could also be binary data, and you would be required
to include a charset as well. I'm definitely missing many things (I didn't
derive it from the existing serialization spec, which is always required
for proper new EWM-friendly APIs), but you get the idea.

Custom Elements should have a way to hook into this serialization protocol,
as people have been discussing on the Custom Elements threads.

New declarative serialization formats could be built on this imperative
API, while still giving people an opportunity to try them out before asking
the platform to add the capability, and without having to rebuild the
entire form serialization protocol as jQuery does. (for example, the jQuery
form serialization system re-implements the "successful control" algorithm).

Extend the Web Forward, my friends.

Yehuda Katz
(ph) 718.877.1325


On Tue, Feb 25, 2014 at 11:19 AM, Brian Kardell <bkardell@gmail.com> wrote:

>
>
>
> On Tue, Feb 25, 2014 at 11:02 AM, Robin Berjon <robin@w3.org> wrote:
>
>> Hi,
>>
>> I put together a small spec to enable having HTML form data submitted
>> directly as JSON, with structure. I'd be curious to hear your feedback:
>>
>>     http://darobin.github.io/formic/specs/json/
>>
>> Thanks!
>>
>> --
>> Robin Berjon - http://berjon.com/ - @robinberjon
>>
>>
>
> Robin,
>
> Some thoughts all over the place...
>
> Would this also modify the FormData serialization in XMLHttpRequest[1].
>  That would be awesomely more useful to me.  It would also be wickedly
> handy if there were a way to get at it (ie, some DOM method), probably more
> useful than even the other two since it would let me polyfill the other two
> with 1 underlying implementation that explains it.   <form>.toObjectModel()
> or something which provides a single canonical non-DOM object
> representation of the form which could be serialized and deserialized could
> be used to explain how enctype="application/json" and corresponding
> FormData in ajax would work too.  Of course, this begs the question of
> whether there is a corresponding <form>.fromObjectModel() which could
> populate the form given some data (kinda awesome), and whether both of
> those are maybe just natively handleable custom serializations ala
> JSON.stringify(form) and JSON.parse(form)..
>
>
> http://www.w3.org/TR/XMLHttpRequest2/#interface-formdata
>
>
>
> --
> Brian Kardell :: @briankardell :: hitchjs.com
>

Received on Tuesday, 25 February 2014 19:39:51 UTC