Would this do the job?
form = SQLFORM.factory(*fields)
if form.process().accepted:
# update the database here
form2 = SQLFORM.factory(*fields)
form2.vars['state'] = form.vars.state
form2.process()
else:
form2 = form
return dict(form=form2)
On Thursday, April 30, 2020 at 2:06:46 PM UTC-4, Jim S wrote:
>
> Here is what I'm talking about:
>
> def update_something():
> fields = [Field('name'),
> Field('address', 'text'),
> Field('city'),
> Field('state'),
> Field('zip_code')]
>
> form = SQLFORM.factory(*fields)
>
> if form.process().accepted:
> # update the database here
>
> return dict(form=form)
>
> After the first time a user updates a record, I want the value of 'state'
> to remain and everything else go back to the defaults. I know I can do it
> by adding some code after form.process().accepted to save the value to the
> session, and then check it before defining the fields, but 'form' doesn't
> exist yet.
>
> I still think I must be missing something here....
>
> -Jim
>
>
> On Thursday, April 30, 2020 at 12:30:44 PM UTC-5, Scott Hunter wrote:
>>
>> Isn't "the next time through the method" when there is a new submission,
>> which would have the saved value in it (unless the user changed it)? Maybe
>> a sample of your code would make things clearer.
>>
>> On Thursday, April 30, 2020 at 1:21:53 PM UTC-4, Jim S wrote:
>>>
>>> Yes, but I need that value on the next time through the method.
>>> Therefore I have to save it to my session and grab it the next time in. Am
>>> I missing something?
>>>
>>> On Thu, Apr 30, 2020 at 12:19 PM Scott Hunter <[email protected]>
>>> wrote:
>>>
>>>> Since the value in question is part of the current submission, isn't
>>>> the value available in form.vars?
>>>>
>>>> - Scott
>>>>
>>>> On Thursday, April 30, 2020 at 12:54:02 PM UTC-4, Jim S wrote:
>>>>>
>>>>> I was hoping to avoid those tricks. I too have done this by storing
>>>>> values in the session to be redisplayed. I was hoping that the keepopts
>>>>> argument to SQLFORM would allow you to specify which fields to keep, but
>>>>> it
>>>>> seems that is used for something else.
>>>>>
>>>>> On Thu, Apr 30, 2020 at 11:48 AM Scott Hunter <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> I recall doing this by "pre-populating" the field you want to keep
>>>>>> with the old value.
>>>>>>
>>>>>> - Scott
>>>>>>
>>>>>> On Thursday, April 30, 2020 at 11:10:42 AM UTC-4, Jim S wrote:
>>>>>>>
>>>>>>> Does anyone know how I can have a form 'keepvalues' but only keep
>>>>>>> one specific field value? I don't want it to keep the values for all
>>>>>>> the
>>>>>>> fields, just for the one specific field.
>>>>>>>
>>>>>>> Anyone tried this before?
>>>>>>>
>>>>>>> -Jim
>>>>>>>
>>>>>> --
>>>>>> 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/tgTvG8OqWso/unsubscribe.
>>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>>> [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/web2py/b4575285-7562-4a55-9470-0adfcbe354f1%40googlegroups.com
>>>>>>
>>>>>> <https://groups.google.com/d/msgid/web2py/b4575285-7562-4a55-9470-0adfcbe354f1%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>> --
>>>> 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/tgTvG8OqWso/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/web2py/14c77d74-1910-4b05-9b88-fac8bef5cf05%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/web2py/14c77d74-1910-4b05-9b88-fac8bef5cf05%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
--
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/17f6caf0-e39a-408b-8b6c-da0bd191247f%40googlegroups.com.