Where do I put the def add_ogranization(form) function? In my user.py controler?
2014-11-12 16:58 GMT+01:00 Leonel Câmara <leonelcam...@gmail.com>: > I would use the autocomplete widget. If you really want a text input and a > combo box I would probably do a custom widget. Here's a full example using > the autocomplete widget, this solution uses the welcome app with this added > to db.py before auth.define_tables(username=False, signature=False) > > db.define_table('organization', > Field('name', requires=IS_NOT_EMPTY()) > ) > > > auth.settings.extra_fields['auth_user'] = [ > Field('organization', 'reference organization', widget=SQLFORM.widgets > .autocomplete(request, db.organization.name, id_field=db.organization.id)) > ] > > > def add_organization(form): > """ > Adds an organization if it doesn't exist, validates all fields. > """ > if not form.vars.organization: > ret = db.organization.validate_and_insert(name=form.vars. > _autocomplete_organization_name_aux) > if ret.errors: > form.errors.organization = ret.errors['name'] > else: > form.vars.organization = ret.id > else: > output, error = IS_IN_DB(db, db.organization.id)(form.vars. > organization) > if error is not None: > form.errors.organization = error > > > auth.settings.register_onvalidation = add_organization > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/AxOk3zS8xUE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Lep pozdrav Vid Ogris -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.