W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

Re: Request for FormData.remove() method

From: Bronislav Klučka <Bronislav.Klucka@bauglir.com>
Date: Thu, 26 Apr 2012 17:43:24 +0200
Message-ID: <4F996D1C.4050401@bauglir.com>
To: public-webapps@w3.org


On 26.4.2012 16:15, Anne van Kesteren wrote:
> On Thu, 26 Apr 2012 15:29:44 +0200, Bronislav Klučka 
> <Bronislav.Klucka@bauglir.com> wrote:
>> On 26.4.2012 13:55, Anne van Kesteren wrote:
>>> Why would you not simply use a JavaScript object for this?
>>
>> Of course you want to use JS object for this in case of storing in 
>> e.g. IDB... the point is, how do you create this object? No, you have 
>> to reimplement FormData construction, instead of using it.
>
> So the reason you want FormData is not because of FormData, it's 
> because FormData has a hook into HTML's "constructing the form data set".
>
> Not really sure what would be the best solution here.
>
>
Hi,
actually what would be the best
1/ be able to get FormData from <form> and then be able to get JS object 
from it
2/ and the vice versa, create FormData (either value by value or from 
object) and assign it to <form> and let the form be filled

I've already encounter both scenarios... If you imagine e.g. users form 
(name, surname, gender, age , address, interests) and the form behind it,
<input type=text name=surname />
<input type=radio name=gender value=male checked />
<input type=text name=address[street] />
<input type=text name=address[country] />
<input type=checkbox name=interest[] value=IT />
<input type=checkbox name=interest[] value=music />

you can imagine that saving it on server can be easy, you create 
FormData and send it... on the other side, you get an object, something like
{
   name: "Brona",
   gender: "male",
   address: {
      street: "B. Smetany",
      country: "cz"
   },
   "interest": [IT, music]
}

but do that in JS itself, is pain, you need to go through all fields, 
validate them (is it valid data? is it not disabled? if text, then get 
value; if radio check for checked and then get value; if multiple 
select...), parse the name, whether it is just field (name), or field 
within object (address[street]), or array(interest[]) or something more 
complex (data[][field][]). At least the task before parsing name is done 
in FormData, even be able to get to those data would be saving of time 
(getting JSON out of it, or object would be even better).

And on the other side, lets say you get JSON/Object representing user 
from server and you need to fill the form back... you need to go 
recursively through  the object and identify the corresponding form 
element.. Why not just fill up FormData and assign them to form? (You 
may also have an object itself, just object, and you may want it to send 
to server... just filling up FormData with that object... without again 
traversing through it..)

So the ability to somehow work with FormData as an object (al least get 
object out of it, or create it based on object) and the ability to get 
FormData from form (that we have) and fill form based on FormData 
(that's missing) would be huge time saver


Brona
Received on Thursday, 26 April 2012 15:44:08 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:52 GMT