I wote a plugin for this last month and I posted on this list but I lost it. If somebody can find it please re-post it.
Massimo On Mar 24, 11:14 am, Abhishek Mishra <ideam...@gmail.com> wrote: > Okay, I will follow that way from now on. > > I have one more doubt, > How do I pre-fill values in an autogenerated SQLFORM? I tried looking > for it but couldn't find a way. > > So, currently in the poll app I made - > page 1. user adds a new poll > page 2. once validated, it takes user to a page where he can add 1 or > more choices to a poll > > I have my tables like these - > db.define_table('poll', > Field('question', length=200, requires=IS_NOT_EMPTY()), > Field('pub_date','datetime', default=request.now, writable=False)) > > db.define_table('choice', > Field('poll', db.poll), > Field('choice', length=200), > Field('votes','integer',default=0)) > > db.choice.choice.requires = IS_NOT_EMPTY() > > So on page 2, where user gets to add choices to poll, I'm again using > SQLFORM, I wish I could prefill the poll number there. > > Currently I'm hiding choice.poll from user in SQLFORM generated form, > and once a new row gets added to choice table, I'm updating like this > - > > def addchoices(): > ''' adds choices to the poll ''' > form=SQLFORM(db.choice,submit_button='Add it', fields=['choice'], > labels={'choice':'Add this choice'}) > if form.accepts(request.vars,session): > last_id = form.vars.id > db(db.choice.id==last_id).update(poll = request.vars.id) > redirect( URL(r=request, f='addchoices', > vars={'id':request.vars.id}) ) > > I wonder if I could have a custom SQLFORM, with very little to modify. > SQLFORM makes me kind of lazy :D > > I loved the way IS_NOT_EMPTY() actually works in the views too. > Hopefully we might use web2py for PyKata. > > Thanks! > > On Mar 24, 9:07 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > My answer was wrong. Your question was correct and I apologize. > > > I checked the code again. > > > I tried: > > > >>> SQLFORM(db.auth_user,fields=['first_name'],labels={'first_name':'Your > > >>> Name'}).xml() > > > '<form action="" enctype="multipart/form-data" > > method="post"><table><tr id="auth_user_first_name__row"><td > > class="w2p_fl"><label for="auth_user_first_name" > > id="auth_user_first_name__label">Your Name</label></td><td > > class="w2p_fw"><input class="string" id="auth_user_first_name" > > name="first_name" type="text" value="" /></td><td class="w2p_fc"></ > > td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td > > class="w2p_fw"><input type="submit" value="Submit" /></td><td > > class="w2p_fc"></td></tr></table></form>' > > > and as you can say it works. > > > Still fields and lables are only there for backward compatibility and > > I consider them deprecated (so much that I forgot about them). I > > recommend using > > > db.table.field.label='....' > > db.table.field.readable=True or False > > db.table.field.writable=True or False > > > form.labels is not defined because according to current design labels > > are a property of the individual fields and not of the form object. > > > On Mar 24, 10:26 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > You do not specify the field labels at the level for the form > > > > form=SQLFORM(...,labels=...) #<<<< WRONG > > > > You specify them at the level of the fields > > > > db.table.field.label='...' > > > form=SQLFORM(db.table) > > > > Massimo > > > > On Mar 24, 9:28 am, Abhishek Mishra <ideam...@gmail.com> wrote: > > > > > Hi guys, > > > > > I am trying to learn/try out web2py from scratch. I'm making a simple > > > > poll application right now. > > > > > So, to add a poll, I'm trying to use automatically generated SQLFORMs > > > > as in - > > > > > pollform=SQLFORM(db.poll, fields=['question'], > > > > labels={'question':'Poll Question'}) > > > > > I was looking for a way to remove submit button from a particular > > > > SQLFORM. > > > > I digged > > > > throughhttp://www.web2py.com/examples/static/epydoc/gluon.sqlhtml-pysrc.html... > > > > and tried things like - > > > > > pollform=SQLFORM(db.poll, fields=['question'], > > > > labels={'question':'Poll Question'}, submit_form='') > > > > pollform=SQLFORM(db.poll, fields=['question'], > > > > labels={'question':'Poll Question'}, submit_form=None) > > > > > ^ None of them actually did the work, is there a way to do this? If > > > > not then would specifying submit_form=None be a nice way to remove the > > > > submit button, or am I missing something? > > > > > Thanks, > > > > > Abhishek -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@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.