Re: serializing elements via $$

Matt Foster
2008-06-25T18:24:18Z

In rereading this i noticed a big error, you''ll have to put a return
on that collect method, my bad...

 arr = $$("form tr").collect(function(row){
     return Form.serializeElements(row.select("input, select,
textarea"));
});


--
Matt Foster
Ajax Engineer
Nth Penguin, LLC
http://www.nthpenguin.com


On Jun 25, 12:08 pm, Matt Foster
<mattfoste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> ew inline event handler! I haven''t seen that in a while...I think
you
> could have an easier time doing something like this...
>
> $$("form tr a").each(function(anchor){
>        var pRow = anchor.up("tr");
>        anchor.observe("click", function(e){
>             alert(Form.serializeElements(pRow.select("input, select,
> textarea"));
>        });
>
> });
>
> Unfortunately you lose a lot of the convenient form references like
> "elements" that access all possible form input objects. I tried
to
> recreate this with the select
methodhttp://prototypejs.org/api/element/select
>
> I am not sure on your entire scope but it might be a worthwhile
> approach to segregate the form into many "mini-forms" that only
> contain the elements you''re after.
>
> This little diddy will give you a collection of each row''s input
> object''s serialized, could be handy...
> arr = $$("form tr").collect(function(row){
>      Form.serializeElements(row.select("input, select,
textarea"));
>
> });
>
> --
> Matt Foster
> Ajax Engineer
> Nth Penguin, LLChttp://www.nthpenguin.com
>
> On Jun 24, 11:26 am, Travis
<Travis.Pax...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Okay, this seems to work.  I''m not sure if its the most
effective way
> > though.
>
> >
> >
> >         <script type="text/javascript"
src="prototype.js">
> >
> >
> >
> >
> >
> >
> > Input 1
> > Input 2
> > Input 3
> >
> >
> >
> >
> >
> >                             <input class="row_data"
type="text"
> > name="data[item][0]" value="abc1" />
> >
> >
> >                             <input class="row_data"
type="text"
> > name="data[item][1]" value="abc2" />
> >
> >
> >                             <input class="row_data"
type="text"
> > name="data[item][2]" value="abc3" />
> >
> >
> >                             <a href="#"
onclick="getRow($
> > (''row_1''));">Serialize Row
> >
> >
> >
> >
> >                             <input class="row_data"
type="text"
> > name="data[item][0]" value="abc4" />
> >
> >
> >                             <input class="row_data"
type="text"
> > name="data[item][1]" value="abc5" />
> >
> >
> >                             <input class="row_data"
type="text"
> > name="data[item][2]" value="abc6" />
> >
> >
> >                             <a href="#"
onclick="getRow($
> > (''row_2''));">Serialize Row
> >
> >
> >
> >
> >
> >
> >             getRow = function(row) {
> >                 alert(Form.serializeElements($(row).descendants()));
> >             }
> >
> >
> >
>
> > On Jun 24, 8:48 am, Travis
<Travis.Pax...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > Is it at all possible to serialize only elements on a form using
the $
> > > $ selector?
>
> > > For example:
>
> > > ...
> > >
> > >
> > >
> > >        <input type="text"
name="data[item]" />
> > >
> > >
> > >
> > >
> > >        <input type="text"
name="data[item]" />
> > >
> > >
> > >
> > > ...
>
> > > And then using prototype to serialize each row:
>
> > >
Form.serialize($(''form'').getElements($$(''#row_1''));
> > >