I hope you can do your solution in controller.
You can set form.vars
AFTER form= definition
and BEFORE form.validate() (or before form.process() which contains
.validate() call)
But you can set the value later too.
Here you have initial name Jan, and substitute name after failed validation
Martin:
def test_name():
form = SQLFORM(db.auth_user)
form.vars.first_name = 'Jan'
if form.process().accepted:
redirect(URL(...))
elif form.errors:
form.custom.widget.first_name.attributes['_value'] = 'Martin'
return dict(form=form)
Dne středa 24. srpna 2016 19:19:25 UTC+2 Gael Princivalle napsal(a):
>
> Thank you Mirek for that.
> Like that it works:
> {{=INPUT(_type='text', _name='book_title', _id='book_title',
> _value='form.vars.book_title')}}
>
> But web2py don't load the default value set in the table (even before it
> was like that but I've add it with _value.
>
> For having a complete solution I must do something like that:
> {{if form.vars.book_title:}}
> {{book_title_value = form.vars.book_title}}
> {{else:}}
> {{book_title_value = 'My book title'}}
> {{pass}}
> {{=INPUT(_type='text', _name='book_title', _id='book_title', _value=
> book_title_value)}}
>
> Il giorno mercoledì 24 agosto 2016 17:20:20 UTC+2, Mirek Zvolský ha
> scritto:
>>
>> form.vars.book_title ? (book, chapter 7)
>>
>>
>>
>>
>> Dne úterý 23. srpna 2016 13:47:34 UTC+2 Gael Princivalle napsal(a):
>>>
>>> Hello.
>>>
>>> In a custom form when the user submit the form with errors I need to
>>> reload all user inputs and set the input value.
>>>
>>> For example here is an input:
>>> {{=INPUT(_type='text', _name='book_title', _id='book_title')}}
>>>
>>> How can I do that ?
>>> As there is available on form errors form.errors.book_title is there
>>> something like form.value.book_title ?
>>>
>>> Thanks.
>>>
>>
--
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.