librelist archives

« back to archive

Subscripting form fields

Subscripting form fields

From:
Dun Peal
Date:
2014-12-16 @ 19:44
I have a form in a table, such that each row represents an entity.

Each row thus contains the same set of fields: name, address, etc.

When I submit the form, I get a whole bunch of fields of the same
name: i.e. for a 100-row table, I get 100 'name' inputs, 100 'address'
inputs, etc.

Is there a reliable way to ensure that I match those fields properly?

I know about form.getlist('name'), but is it always guaranteed to be
in order, so I can assume that for any i, form.getlist('name')[i] will
match form.getlist('address')[i]

Thanks, D.

Re: [flask] Subscripting form fields

From:
David Baumgold
Date:
2014-12-16 @ 19:48
No, it’s not guaranteed to be in any particular order. You’re better off 
using some kind of numbering scheme: each row has a number, and that 
number is incorporated into the “name” attribute of each field in that 
row. Then you can reconstruct the rows on the server side by checking the 
numbers.

David Baumgold

From: Dun Peal <dunpealer@gmail.com>
Reply: flask@librelist.com <flask@librelist.com>>
Date: December 16, 2014 at 2:46:16 PM
To: flask@librelist.com <flask@librelist.com>>
Subject:  [flask] Subscripting form fields  

I have a form in a table, such that each row represents an entity.  

Each row thus contains the same set of fields: name, address, etc.  

When I submit the form, I get a whole bunch of fields of the same  
name: i.e. for a 100-row table, I get 100 'name' inputs, 100 'address'  
inputs, etc.  

Is there a reliable way to ensure that I match those fields properly?  

I know about form.getlist('name'), but is it always guaranteed to be  
in order, so I can assume that for any i, form.getlist('name')[i] will  
match form.getlist('address')[i]  

Thanks, D.  

Re: [flask] Subscripting form fields

From:
Moritz Beber
Date:
2014-12-16 @ 20:30
If you use wtforms and some type of multiple field, it will give each field
a consecutively numbered id and thus a guaranteed matching.
On Dec 16, 2014 8:52 PM, "David Baumgold" <david@davidbaumgold.com> wrote:

> No, it’s not guaranteed to be in any particular order. You’re better off
> using some kind of numbering scheme: each row has a number, and that number
> is incorporated into the “name” attribute of each field in that row. Then
> you can reconstruct the rows on the server side by checking the numbers.
>
> David Baumgold
>
> From: Dun Peal <dunpealer@gmail.com> <dunpealer@gmail.com>
> Reply: flask@librelist.com <flask@li brelist.com>> <flask@librelist.com>
> Date: December 16, 2014 at 2:46:16 PM
> To: flask@librelist.com <flask@librelist.com>> <flask@librelist.com>
> Subject:  [flask] Subscripting form fields
>
> I have a form in a table, such that each row represents an entity.
>
> Each row thus contains the same set of fields: name, address, etc.
>
> When I submit the form, I get a whole bunch of fields of the same
> name: i.e. for a 100-row table, I get 100 'name' inputs, 100 'address'
> inputs, etc.
>
> Is there a reliable way to ensure that I match those fields properly?
>
> I know about form.getlist('name'), but is it always guaranteed to be
> in order, so I can assume that for any i, form.getlist('name')[i] will
> match form.getlist('address')[i]
>
> Thanks, D.
>
>