Hardcoded Drop Down Menu In Form

88 views
Skip to first unread message

Pablo Cruise

unread,
Nov 25, 2014, 6:47:13 PM11/25/14
to web...@googlegroups.com
I'm a novice Web2py programmer and I've searched the net but can't figure this out.

I've got a simple webpage with this form:

    form = FORM(TABLE(TR
            (TH('BEG PLAN START DATE'), INPUT(_name='begpstrtdt', _class='date', requires=IS_DATE(), _value=t0, _style="width: 100px;")),
            (TH('END PLAN START DATE'), INPUT(_name='endpstrtdt', _class='date', requires=IS_DATE(), _value=t0, _style="width: 100px;")),
            TR('Group',INPUT(_name='group', _id='group', , requires=IS_IN_SET(['YES', 'NO']))),        
            TR('Email Results?',INPUT(_name='emailflg', _id='emailflg', _type='checkbox', _value='0')),
            TR('Show Query?',INPUT(_name='qryflg', _id='qryflg', _type='checkbox', _value='1', _checked="checked",
             _onclick="if(jQuery('#qryflg').prop('checked')) jQuery('#qryinfo').show(); else jQuery('#qryinfo').hide();")),             
            TR('Show Debug?',INPUT(_name='dbgflg', _id='dbgflg', _type='checkbox', _value='1', _checked="checked",
             _onclick="if(jQuery('#dbgflg').prop('checked')) jQuery('#dbginfo').show(); else jQuery('#dbginfo').hide();")),
            TR(INPUT(_type='submit',_value='Submit'))
            ))



Everything works except I can't get the Group dropdown, 3rd element, to be a dropdown menu.  It shows up as a text field.

1. Is there an attribute I'm missing in the description?
2. How would I get the selected value?

I've seen many example using SQLFORM but I don't have a need for these fields to be saved or retrieved to/from a database.

Thanks,
Paul

Johann Spies

unread,
Nov 26, 2014, 1:26:18 AM11/26/14
to web...@googlegroups.com
On 26 November 2014 at 01:47, Pablo Cruise <pal...@gmail.com> wrote:
I'm a novice Web2py programmer and I've searched the net but can't figure this out.


I've seen many example using SQLFORM but I don't have a need for these fields to be saved or retrieved to/from a database.


Why don't you use SQLFORM.factory? 

A quote from the web2py-book:

There are cases when you want to generate forms as if you had a database table but you do not want the database table. You simply want to take advantage of the SQLFORM capability to generate a nice looking CSS-friendly form and perhaps perform file upload and renaming.


Regards
Johann

--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

T.R.Rajkumar

unread,
Nov 26, 2014, 4:08:38 AM11/26/14
to web...@googlegroups.com
Its not INPUT. Its SELECT. See the code below.
def get_shifts():
   
return ["1","2","3","G"]


shifts
= get_shifts()

form
= FORM(TABLE(
                      TR
('AgtNo:',SELECT(_name='cmbAgtNo',_id='cmbAgtNo', requires=IS_NOT_EMPTY(),*[OPTION(str(x.agt_no) + x.work_desc,_value=x.id) for x in agts] )),
                      TR
('Jcod:',SELECT(_name='cmbJcod', _id='cmbJcod', requires=IS_NOT_EMPTY(), *[OPTION(x.jcod + '|' + x.job_desc, _value=x.jcod) for x in jobs])),
                      TR
('MeasDate:',INPUT(_type='text', _name='txtMeasDate',_id='txtMeasDate', _class='date', requires=IS_NOT_EMPTY() )),
                      TR
('Shift:',SELECT(_name='cmbShift', _id='cmbShift', requires=IS_NOT_EMPTY(),*[OPTION(x,_value=x) for x in shifts])),
                      TR
('',INPUT(_type='submit',_value='CreateMeas'))
                     
))re...

Pablo Cruise

unread,
Dec 2, 2014, 3:21:02 PM12/2/14
to web...@googlegroups.com
Thanks Johann. I need to take some time and fully read and analyze the Web2py book.  I'll try SQLFORM on a future form.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/4FFlABaDmQ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pablo Cruise

unread,
Dec 2, 2014, 3:21:10 PM12/2/14
to web...@googlegroups.com
Thanks TR.  That worked great!

--
Reply all
Reply to author
Forward
0 new messages