I prefer to use crud, but it is not qualified for your workaround I
think.
On the other hand, you said that there is a "custom" widget which
interfere with validators. Is it possible that I switch "back" to an
old style widget, which respects validators? Because I need server
side validation more than an appealing UI.
I've tried this, still no luck. When submit, ticket occurs. Do you see
a chance here?
...
Field('participants', 'list:reference employee',
requires = [IS_NOT_EMPTY(),
IS_LIST_OF(IS_IN_DB(db,'employee.id',db.employee._format,multiple=True))],
widget = SQLFORM.widgets.list.widget, # default is "multiple"
widget
)
Regards,
Ray
On Jul 24, 9:54 pm, Massimo Di Pierro <[email protected]>
wrote:
> try one more thing:
>
> form = SQLFORM(....)
> form.element('input#appointment_participants')
> ['requires']=IS_NOT_EMPTY()
> if form.accepts(...)
>
> The problem is that the custom widget interfere with validators and
> validators may have to be attached to the widget.
>
> On Jul 24, 8:22 am, Iceberg <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi Massimo,
>
> > Thanks for trying to help. Perhaps I did not clearly explain the
> > point.
>
> > I hope to add an IS_NOT_EMPTY() constraint to any "list:reference
> > table_name" field. My previous snippet is copied from web2py book, but
> > in my real need, that "list:reference" field is not necessary a tag.
> > So I'm not going to plugin_tagging or plugin_wiki direction. Instead
> > you can think about a booking system inside a company.
>
> > db.define_table('employee', Field('name'))
> > db.define_table('appointment',
> > Field('subject', 'string'),
> > Field('participants', 'list:reference employee'),
> > )
>
> > So I don't need any comma-separated-employee-name UI. In fact the
> > default widget for list:reference is already great. What I need is
> > just make sure any appointment will have at least one participant.
>
> > Can we somehow hook a IS_NOT_EMPTY() into list:reference 's default
> > widget? Thanks!
>
> > Regards,
> > Ray (a.k.a. Iceberg)
>
> > On Jul 24, 3:16 pm, Massimo Di Pierro <[email protected]>
> > wrote:
>
> > > I understand and what you need to do is a bit more complex than needs
> > > to be. For this reason we have plugin_tagging and tagging in
> > > plugin_wiki. Another approach is the following...
>
> > > class TAGGING:
> > > def __call__(self,field,value):
> > > return INPUT(_name='%s_%s' % (field._tablename,field.name),
> > > _value=', '.join(r.name for r in
> > > db(db.tag.id.belongs(value or [])).select()),
> > > requires = self.validate)
> > > def validate(self,tags):
> > > names = [x.strip() for x in tags.split(',')]
> > > ids = [r.id for r in
> > > db(db.tag.name.belongs(names)).select()]
> > > if len(ids) < len(names):
> > > return (ids, "one of the tags is invalid or repeated")
> > > return (ids,None)
>
> > > 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',widget=TAGGING()),)
>
> > > def testme():
> > > return {
> > > 'a': crud.update(db.product, request.args(0)),
> > > 'b': crud.select(db.product),
> > > }
>
> > > The custom TAGGING widget renders the list of IDS as a a list of comma-
> > > separated names. You can also cache the mapping between ids and tag
> > > names for speed.