Perfect, Thank You!  I didn't realize that IS_IN_SET() had a labels
argument available that would set the text to be shown in the select
box.  So many little treasures hidden away in web2py :)

>From the epydocs for web2py.gluon.validators.IS_IN_SET()
    __init__(self, theset, labels=None, error_message='value not
allowed', multiple=False, zero=None)

So the following solves my needs:

weekdays =
("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
#these will be the "labels" for our select field
form = SQLFORM.factory(
    Field("days", label = "Desired Day(s) of the Week",
requires=IS_IN_SET(range(1,8),labels=weekdays, multiple=True)))

On Jan 1, 10:39 am, mdipierro <[email protected]> wrote:
> weekdays =
> ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
> form = SQLFORM.factory(Field('dow',requires=IS_IN_SET(range
> (1,8),weekdays,multiple=True)))
>
> On Jan 1, 12:32 am, Brian M <[email protected]> wrote:
>
>
>
> > How would I go about creating a select field with SQLFORM.factory that
> > gives output like this?
>
> > <select name="dow" multiple="multiple">
> > <option value="1">Monday</option>
> > <option value="2">Tuesday</option>
> > <option value="3">Wednesday</option>
> > <option value="4">Thursday</option>
> > <option value="5">Friday</option>
> > <option value="6">Saturday</option>
> > <option value="7">Sunday</option>
> > </select>
>
> > I know that I can do it with regular FORM like this:
>
> > weekdays = [[1,"Monday"],[2, "Tuesday"],[3,"Wednesday"],[4,"Thursday"],
> > [5,"Friday"],[6,"Saturday"],[7,"Sunday"]]
> > weekday_options = [OPTION(day[1],_value=day[0]) for day in weekdays]
> > FORM(SELECT(*weekday_options,**dict
> > (_name="dow",_multiple='multiple',requires=IS_IN_SET
> > ([1,2,3,4,5,6,7]))))
>
> > But I can't figure it out with SQLFORM.factory, which I'd like to use
> > so I can do custom form layouts. (Well, I could do it if the weekdays
> > were in a db table, but that seems silly). I'm sure I am missing
> > something simple and obvious.
>
> > ~Brian

--

You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to