That's interesting and more clean but in my case I don't use the widget as
I would like to add to the input an input-group-addon for having for
example for this field 'daily-distance' the unit at the end.
<div class='form-group'>
{{=LABEL(T(db.events.daily_distance.label),
_for='daily_distance')}}:
<div class="input-group">
{{if form_event.vars.daily_distance:}}
{{daily_distance_value =
form_event.vars.daily_distance}}
{{else:}}
{{daily_distance_value = '5'}}
{{pass}}
{{=INPUT(_type='text', _name='daily_distance',
_id='daily_distance', _class='form-control', _value=daily_distance_value,
_onchange='update_data()')}}
<span class='input-group-addon'>
{{=SPAN(T(db.events.daily_distance.comment),
_class='comment')}}
</span>
</div>
{{if form_event.errors.daily_distance:}}
<div class="error_wrapper">
<div id="daily_distance__error" class="error" style=
"display: inline-block;">
{{=form_event.errors.daily_distance}}
</div>
</div>
{{pass}}
</div>
It works also with the widget:
<div class="form-group">
{{=LABEL(T(db.events.daily_distance.label),
_for='title')}}:
<div class="input-group">
{{=form_event.custom.widget.daily_distance}}
<span class='input-group-addon'>
{{=SPAN(T(db.events.daily_distance.comment),
_class='comment')}}
</span>
</div>
</div>
But in case of errors the error_wrapper class is added inside the
input-group, so it increase the input-group-addon height:
<https://lh3.googleusercontent.com/-35T7RIUtkSE/V79PydbSM4I/AAAAAAAAGc0/FBPaTWU52usVz9sCLky0-4ycbtZGBeq_QCLcB/s1600/Schermata%2B2016-08-25%2Balle%2B22.03.30.png>
It's not nice and I don't know how I can say to web2py to add the
error-wrapper after the input-group. Do you know that?
Il giorno giovedì 25 agosto 2016 14:07:23 UTC+2, Mirek Zvolský ha scritto:
>
> 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.