or in one line

form=SQLFORM.factory(*[Field(item) for item in list])

On Oct 29, 2:41 pm, Chris S <sanders.ch...@gmail.com> wrote:
> That's great, I'm sure I'll find all sorts of places that's useful now
> that I know about it.
> Now that I can dynamically build my Fields for my list, I've tried to
> go back and put a requirement on them for validation.  You can't use
> keywords in a list so I'm a little stumped.
>
> Is there a suggestion for editing this code to insert 'requires'
> statements?  Or possibly can I just set one global requires?  In my
> case all values are INTS in the same range.
> ----
> for item in list:
>      fields.append(Field(item))
>
> form=SQLFORM.factory(*[fields[num] for num in range(len(fields))])
> ----
>
> If the 'requires' statement didn't have to go IN the field statement I
> was thinking the ** notation with a keyword of 'requires' and a value
> of 'IS_INT_IN_RANGE(0,100)' might help, but it's got to go IN the Field
> (item) statement not just appended to the list after it.
>
> Any suggestions?
>
> On Oct 29, 10:43 am, Jonathan Lundell <jlund...@pobox.com> wrote:
>
> > On Oct 29, 2009, at 8:36 AM, Chris S wrote:
>
> > > lol, well I've been all around that.  Thank you so much, works just
> > > fine now.
>
> > > Is there a quick 2-min "why that works" or somewhere you could point
> > > me to as to what that * means/does?  Apparently I'm missing out on
> > > something important.
>
> > It's a Python thing. Check out 5.3.4 here:
>
> >http://docs.python.org/reference/expressions.html#calls
>
> > > On Oct 29, 10:33 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > >> form=SQLFORM.factory(*[fields[num] for num in range(len(fields))])
>
> > >> On Oct 29, 10:25 am, Chris S <sanders.ch...@gmail.com> wrote:
>
> > >>> I've been trying to get a form built where the number of Fields are
> > >>> dynamic.  I was successful with the plan form by using:
> > >>> ------------Form Implementation------------------------
> > >>> fields=[]
> > >>> for item in list:
> > >>>         fields.append(item)
> > >>>         fields.append(INPUT(_name=item,requires=IS_INT_IN_RANGE
> > >>> (0,100,error_message=('Must be an Int 0 to 100'))))
> > >>> fields.append(INPUT(_type='submit'))
>
> > >>> form=FORM([fields[num] for num in range(len(fields))])
> > >>> ------------Form Implementation------------------------
>
> > >>> I can append items to my form but the output in HTML is nasty.
> > >>> Everything is just crammed together.  I read about form.custom and  
> > >>> was
> > >>> going to use that approach but apparently I have to use the
> > >>> SQLFORM.factory() to use that.  Attempting the same thing in
> > >>> SQLFORM.factory() looks like
>
> > >>> ------------SQLFORM.factory() Implementation------------------------
> > >>> fields.append(Field('item1'))
> > >>> fields.append(Field('item2'))
>
> > >>> form=SQLFORM.factory(fields[0])
> > >>> #This works, but obviously isn't dynamic I only get the first entry.
>
> > >>> form=SQLFORM.factory(fields[num] for num in range(len(fields)))
> > >>> #This errors with "define_table argument is not a Field: <generator
> > >>> object at 0x110BD7B0>"
> > >>> ------------SQLFORM.factory() Implementation------------------------
>
> > >>> Can anyone help me out here?  I want to be able to arrange the  
> > >>> fields
> > >>> in HTML like I want (which I can't seem to do with just the simple
> > >>> form), but I also want to be able to build the fields dynamically
> > >>> which I can't seem to get working with SQLFORM.factory().  I'm sure
> > >>> I'm missing something easy, this can't be as hard as I'm making it.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to