On Sunday, January 22, 2017 at 2:56:07 PM UTC-8, Val K wrote:
>
> The problem is that one controller is used for generation and process 
> form. it's like different modes 
> pre-populating form by assignments  form.vars.name=...   could be used 
> only for the request form, when form is submitted these assignments have no 
> effect.
> if you want to change anything  in the form after it was processed, you 
> have to use  DOM-parsing ( something like  form[0].element('input', 
> _name='...')['_value'] = ... )
>
> Use keepvalues=True or  db.table.field.default  as suggested above (it 
> does the  pre-populating during form.process())
> There is brute force variant  -   self-redirection :  if 
> form.process().accepted: ... *session.*flash='OK';  redirect(URL())  - 
> but don't forget about args/vars/user_signature  if it matters
>
>
>
Okay, I guess I was expecting submission to result in a fresh form 
creation, but it takes the self-redirection to acheive that, eh?

/dps

 

> On Sunday, January 22, 2017 at 11:58:06 PM UTC+3, Dave S wrote:
>>
>>
>>
>> On Sunday, January 22, 2017 at 2:50:16 AM UTC-8, Val K wrote:
>>>
>>> Pre-populating - means just default values  which will be overwritten 
>>> during form.process(), i.e.  form.process() reads vars values only from 
>>> request.*post_*vars  or from 'vars' arg  - form.process(vars = {...} ) 
>>> and ignores  pre-sets like form.vars.name=... 
>>>
>>> There was a mistake in my  post: instead  request.vars  must be request.
>>> *post_*vars -   I fixed this 
>>>
>>>
>>
>> But default is what I want!  If I didn't want to be able to change the 
>> value when filling out the form, I wouldn't even need to provide the field.
>>
>> /dps
>>
>>  
>>
>>> On Sunday, January 22, 2017 at 12:48:45 PM UTC+3, Dave S wrote:
>>>>
>>>>
>>>>
>>>> On Friday, January 20, 2017 at 9:23:37 AM UTC-8, Val K wrote:
>>>>>
>>>>> form.vars appear only after form.process()  call (process() - 
>>>>> filter/convert/format/validate request.vars to form.vars)
>>>>> you have variants :
>>>>> 1. *before *form creation  - modify field.default
>>>>> 2. *before* form.process()  -  modify request.vars - 
>>>>> request.vars.PostDate=... 
>>>>> 3. pass your own set of vars  -  form.process(vars=myvars)
>>>>> 4. use form.process( onvalidation=myvalidation_fun) to modify 
>>>>> form.vars  *after *basic validation passed but before any db actions
>>>>>  
>>>>>  
>>>>>
>>>>>
>>>> But what about this passage in the book?
>>>>
>>>> <URL:
>>>> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Pre-populating-the-form
>>>> >
>>>> Pre-populating the form
>>>>
>>>> It is always possible to pre-populate a form using the syntax:
>>>>
>>>> 1
>>>>
>>>> form.vars.name = 'fieldvalue'
>>>>
>>>> Statements like the one above must be inserted after the form 
>>>> declaration and before the form is accepted, whether or not the field 
>>>> ("name" in the example) is explicitly visualized in the 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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to