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