>From the user-interface aspect, of course we expect end user to input real names, rather than IDs. Actually web2py already provides a nice- looking multi-selection widget by default, in scenario 1 of my first post.
The only and real problem right now, is that end user can add/edit a record with its list:reference field being empty. I hope to add an IS_NOT_EMPTY() constraint on it. Hope I explain it clear. If not, feel free to ask me again. Thanks! Regards, Ray On Jul 24, 1:07 am, Massimo Di Pierro <[email protected]> wrote: > I see what the problem is. The default widget overrides the validator. > Before we look for a solution let me undertand what you need. > > The way you phrased looks like you want users to input the IDs of the > tags. I suspect you want instead the user to insert tag names, perhaps > comma separated, and you want the system to parse them and store the > corresponding ids in the product.tags field. Is this correct? > > massimo > > On Jul 23, 2:52 am, Iceberg <[email protected]> wrote: > > > > > > > > > Hi Massimo, > > > How to add a IS_NOT_EMPTY constrait to list:reference field? This > > seems a simple task but I ends up opening a can of worms. :-/ Here is > > what I did. > > > 1. Firstly, setup the sandbox. > > > db.define_table('tag', > > Field('name', requires=IS_NOT_EMPTY()), format='%(name)s') > > db.define_table('product', > > Field('name', requires=IS_NOT_EMPTY()), > > Field('tags', 'list:reference tag'),) > > > def product(): > > return { > > 1: crud.update(db.product, request.args(0)), > > 2: crud.select(db.product), > > } > > > Now we can add new product with or without tags. Fine. > > > 2. What if we need new product to have at least one tag? > > > I tried changing the tags field definition into (I thought it was > > intuitive): > > > Field('tags', 'list:reference tag', required=True) > > > But nothing different. I can't force a tag. > > > 3. Then I tried to change tags into: > > > Field('tags','list:reference tag', > > requires = > > IS_IN_DB(db,'tag.id',db.tag._format,multiple=True),), > > > This is the so-called default constraint, according to the book, > > chapter 6. > > But situation gets worse. Now I get error ticket whenever submitting > > new product. > > > 4. I even tried: > > > requires = [IS_NOT_EMPTY(), IS_IN_DB(...)] > > > still tickets. > > > Problem persists in both web2py 1.95.1 and 1.97.1, on Windows. > > > Did I miss something really obvious? Thanks in advance. > > > Regards, > > Ray (a.k.a. Iceberg)

