On Thursday, September 5, 2013 11:04:53 AM UTC+2, Gliese 581 g wrote:
>
> Hi,
>
> I have a cutom form which I am displaying using SQLFORM.factory as given
> below:
>
> searchform=SQLFORM.factory(
> Field('uid', 'integer', requires=[IS_LENGTH(15,15)]),
> Field('uaccount','unicode',default=None))
> if searchform.accepts(request.vars):
> result=__get_payments()
> else:
> response.flash = 'please fill the form'
> return dict(form=searchform)
>
> I have 2 questions here which are given as follows:
>
> 1. I want *uid* must be an integer and form should not be accepted
> if string value is supplied.
> But even if I enter string value in uid field, it still accepts the
> form.What do I do to achieve this?
>
Setting requires=IS_LENGTH() "killed" the IS_INT_IN_RANGE() default
validator for integers.
>
> 2. If *uaccount *is not supplied, I want it to be None. But when I try to
> access it using request.vars.uaccount, I get empty string value. I think I
> should rather get None value. Please suggest.
>
>
If you want a request.vars.something to be None, it should not exist in the
list of the sent values (meaning, it shouldn't be included as an input in
the form). In HTML there's no such thing as "Null" for an input value, you
get the closest representation of that with an empty field, that gets sent
with a value of '' . Use your own logic if you want "None" when the user
leaves out the field.
> Thank you.
>
>
--
---
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/groups/opt_out.