It is actually the IS_NOT_EMPTY validator that strips the whitespace (it
does this so a string containing only spaces will be considered empty). You
can either create your own custom validator, or do something like:
requires=lambda v: (v, IS_NOT_EMPTY()(v)[1])
The above returns the original value along with the error message (if any)
from IS_NOT_EMPTY.
Anthony
On Friday, February 10, 2017 at 8:11:18 AM UTC-5, Andriy wrote:
>
> fields = [ Field('name', 'string', default=defaults['name'],
> requires=[IS_NOT_EMPTY(error_message='Enter name')]), ]
> form = SQLFORM.factory(*fields, _class="uk-form uk-form-horizontal",
> _name="edit_form")
> if form.process(hideerror=True).accepted:
> print (form.vars.name, request.vars.name)
>
> If I enter "Bob " (with trailing space in input field) I get printed:
> ('Bob', 'Bob ')
>
> form.vars.name looses trailing space and I didn`t ask for this.
> request.vars.name is correct.
>
> I do *form.vars.name <http://form.vars.name> = request.vars.name
> <http://request.vars.name>* later in my code to counter this. I need all
> spaces preserved as they are entered. I didn`t find any explanation for
> this in the help/book.
>
--
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.