IS_LIST_OF takes a "minimum" argument, which defaults to 0, so it should 
still validate if no items are submitted (it also takes a "maximum" 
argument). If that's what you're looking for, you shouldn't need 
IS_EMPTY_OR at all (note, IS_NULL_OR has been deprecated).

As for errors, when a validation error occurs with IS_LIST_OF and the list 
widget, the errors will be in form.errors, but they will not be displayed 
on the form by default (it's complicated, and when we added support for the 
IS_LIST_OF validator, we didn't work that out). So, you're responsible for 
checking form.errors and deciding how you want to communicate the error in 
the UI.

Anthony

On Friday, March 30, 2012 9:54:41 AM UTC-4, Fran wrote:
>
> I am trying to make use of the cool 'new' (to me) grow_input which is the 
> default widget for a list:integer
>
> I want to validate against an IS_IN_SET(), so looking at the code, I see 
> that this requires using IS_LIST_OF() (other validators get ignored)
>
> I see this as the suggested way to use it:
>
> https://groups.google.com/forum/?fromgroups#!newtopic/web2py/web2py/6-7TSMqUgBU
>
> However this doesn't work - with the multiple=True in there I get:
>
> File "C:\Bin\web2py\gluon\dal.py", line 1456, in represent
>     obj = [int(item) for item in obj]
> TypeError: int() argument must be a string or a number, not 'list'
>
>
> If I remove the multiple=True, then it works, however there remain 2 problems:
>
>
> I cannot find a way to get an IS_NULL_OR() - I can't do it around the 
> IS_LIST_OF as the requires is stripped then.
>
> If I put it inside the IS_LIST_OF() & put in a null value I get:
>
>   File "C:\Bin\web2py\gluon\html.py", line 2004, in process
>     self.validate(**kwargs)
>   File "C:\Bin\web2py\gluon\html.py", line 1951, in validate
>     if self.accepts(**kwargs):
>   File "C:\Bin\web2py\gluon\sqlhtml.py", line 1290, in accepts
>     self.vars.id = self.table.insert(**fields)
>   File "C:\Bin\web2py\gluon\dal.py", line 7030, in insert
>     ret =  self._db._adapter.insert(self,self._listify(fields))
>   File "C:\Bin\web2py\gluon\dal.py", line 968, in insert
>     query = self._insert(table,fields)
>   File "C:\Bin\web2py\gluon\dal.py", line 964, in _insert
>     values = ','.join(self.expand(v,f.type) for f,v in fields)
>   File "C:\Bin\web2py\gluon\dal.py", line 964, in <genexpr>
>     values = ','.join(self.expand(v,f.type) for f,v in fields)
>   File "C:\Bin\web2py\gluon\dal.py", line 1100, in expand
>     return str(self.represent(expression,field_type))
>   File "C:\Bin\web2py\gluon\dal.py", line 1456, in represent
>     obj = [int(item) for item in obj]
> TypeError: int() argument must be a string or a number, not 'NoneType'
>
>
> The other issue I have is that form.errors isn't working properly.
> I get no error inline with the field when there are errors.
> I can see that the widget has hideerror=True, so this appears to be 
> deliberate:
> https://github.com/mdipierro/web2py/blob/master/gluon/sqlhtml.py#L223 
>
> I tried changing that, but no joy...tracing through I see that the 
> self.errors only appear for the other fields (text/submit) & then is 
> rejected because the name doesn't match...
> https://github.com/mdipierro/web2py/blob/master/gluon/html.py#L1655 
> self.errors = Storage: <Storage {'membership_paid': 'value not allowed'}>
>
> Simple test case I used to debug the problem in isolation:
> Model:
> db.define_table("test",
>                     Field("text", requires=IS_NOT_EMPTY()),
>                     Field("membership_paid", "list:integer",
>                           label = T("Membership Paid"),
>                           requires = IS_LIST_OF(IS_IN_SET([2010,2012])),
>                           ))
>
> Controller:
> def index():
>     form = SQLFORM(db.test)
>     if form.process().accepted:
>         response.flash = 'form accepted'
>     elif form.errors:
>         response.flash = 'form has errors'
>     else:
>         response.flash = 'please fill out the form'
>     return dict(form=form)
>
> Any help welcome on resolving these 2 issues :)
>
> Many thanks,
> Fran.
>

Reply via email to