FORM and <select>

4 views
Skip to first unread message

annet

unread,
Nov 26, 2008, 9:42:38 AM11/26/08
to web2py Web Framework
In a controller I have got the following code to build a form:

form=FORM('Type een plaatsnaam:',
INPUT(_name='plaatsnaam',requires=IS_NOT_EMPTY()),
'Selecteer een activiteit:'
SELECT(_name='training',requires=IS_IN_DB
(db,'training.training','%(training)s')),
INPUT(_type='submit'))


In my model,

db.bedrijftraining.training.requires=IS_IN_DB(db,
'training.training','%(training)s')

results in a drop down list in the admin, I had hoped to achieve the
same in the form above using the following line of code:

SELECT(_name='training',requires=IS_IN_DB(db,'training.training','%
(training)s')),

,however, this line results in an error, does one of you know how to
implement a drop down list in FORM?


Best regards,

Annet.

mdipierro

unread,
Nov 26, 2008, 10:10:03 AM11/26/08
to web2py Web Framework
FROM is just a helper (makes <form>...</form>) and it is not much
smarter than that. You can use form_factory or

options=[OPTION(k,_value=v) for v,k in db.training.training.options()]

> form=FORM('Type een plaatsnaam:',
> INPUT(_name='plaatsnaam',requires=IS_NOT_EMPTY()),
> 'Selecteer een activiteit:'
> SELECT(_name='training',requires=IS_IN_DB
> (db,'training.training','%(training)s'),*options),
> INPUT(_type='submit'))

annet

unread,
Nov 27, 2008, 12:35:23 PM11/27/08
to web2py Web Framework
Massimo,

I solved this problem building the form in form_factory.


Annet.

annet

unread,
Dec 8, 2008, 8:16:31 AM12/8/08
to web2py Web Framework
As I said: I solved this problem building the form in form_factory.

trainingrows=db().select(db.bedrijftraining.training,distinct=True)
traininglist=[trainingrows[i]['training'] for i in range(len
(trainingrows))]
form=form_factory(SQLField('training', label='Selecteer een
activiteit',requires=IS_IN_SET(traininglist)))


The IS_IN_SET() list is based on a database table, now I would like to
convert the following form into a IS_IN_SET() list:

<select name="dagen">
<option value="14" selected="selected">2 weken</option>

  <option value="28">4 weken</option>

  <option value="56">8 weken</option>
</select>


And use the list like this:

dayslist[]
form=form_factory(SQLField('dagen', label='Selecteer een aantal
weken',requires=IS_IN_SET(dayslist)))


I searched this group for an answer, but didn't find a solution with
respect to label/value pairs.


Best regards,

Annet.
Reply all
Reply to author
Forward
0 new messages