On Friday, April 22, 2016 at 7:41:52 AM UTC-7, Anthony wrote:
>
> If you want to prefill form fields, the best method is to set the field
> defaults (before creating the form):
>
> db.str1.dt.default = request.now
>
> Anthony
>
>
Thanks, Anthony. That application is at home, so I'll check it out later.
This doest seem to be one the places where the book is less clear.
Also, is there a difference between
form.process().accepted
and
form.process()
form.accepted
?
> On Friday, April 22, 2016 at 2:22:09 AM UTC-4, Dave S wrote:
>>
>> I seem to be missing something.
>>
>> I have a simple table:
>>
>> db.define_table("str1",
>> Field('x1', 'string', requires=IS_NOT_EMPTY()),
>> Field('dt', 'datetime'))
>>
>> And a simple controller.
>>
>> def example1():
>> form = SQLFORM(db.str1)
>> form.vars.dt = request.now
>> form.vars.x1 = 'lasdfjl'
>> form.process()
>> print request.now
>> print form.vars
>> if form.accepted:
>> message=form.vars.x1
>> response.flash='good job, Dave'
>> elif form.errors:
>> message='you have errors, Dave'
>> else:
>> message="what did you do?"
>> return dict(message=message, form=form)
>>
>>
>>
>> When I get to the print statements, the console shows what I expect (the
>> values I filled out the form with). But the form as rendered does not show
>> anything until I enter something, and if I submit without entering
>> anything, the process() yields form.errors, with "enter a value" under x1,
>> and the print statement shows dt and x1 as None and empty.
>>
>> What am I not doing, such that setting form.vars.x1 and form.vars.dt
>> doesn't get displayed in the form, and they aren't used as values if I
>> don't enter anything?
>>
>> /dps
>>
>>
--
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 the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.