I see that it's non-trivial but maybe 1,3 and 4 could be negated by using the following syntax (2 I'm not so sure about)...
COMPOUNDFORM( db.TABLE1,db.TABLE2, db.TABLE3, fields= [ db.TABLE1.name, db.TABLE2.email, db.TABLE3.phone ], relations [ db.TABLE1.id==db.TABLE2.contact_id, db.TABLE1.id==db.TABLE3.contact_id ] ) Anyway, if I can't use SQLFORM the issue for me now is how to achieve this by other means. Is there a way to generate individual form fields from the model such that the model's constraints are imposed on A) the submitted values and B) the client side javascript? Or do I have to duplicate these conditions at the controller level manually? Would it be a good idea to use form_factory to build such a form? Thanks, Roger. On Apr 4, 11:27 am, mdipierro <[email protected]> wrote: > what you say could be implemented but it would not be general enough > to satisfy every user. > 1) why be limited to two tables > 2) is this a one-to-one or one-to-many? > 3) in which order the fields should be listed > 4) what if the two tables have fiends with the same name > ... > > there are many issue that make this a non-trivial problem. Eventually > it will be done but requires some work. > > Massimo > > On Apr 4, 9:15 am, "[email protected]" > > <[email protected]> wrote: > > Hi All, > > > I must be missing something, I've read the book's chapter on SQLFORM > > and the bit about "Links to referencing records" but I still can't get > > my head round how to make a compound form, i.e. one with fields from > > multiple tables. Here's are my tables... > > > db.define_table('CONTACTS', > > SQLField('contact_name','string',length=255, required=True), > > SQLField('date_added','datetime', required=True) > > ) > > db.CONTACTS.contact_name.requires=[ IS_NOT_EMPTY(), IS_LENGTH > > (255,error_message=T('name too long, max(255)')) ] > > db.CONTACTS.date_added.requires=[ IS_DATETIME() ] > > > db.define_table('EMAIL_ADDRESSES', > > SQLField('contact_id',db.CONTACTS, required=True), > > SQLField('email_address','string',length=255, required=True), > > SQLField('the_default','boolean', default=False, required=True) > > ) > > db.EMAIL_ADDRESSES.contact_id.requires=[ IS_IN_DB(db, > > db.CONTACTS.id) ] > > db.EMAIL_ADDRESSES.email_address.requires=IS_EMAIL() > > > This is my view... > > > def index(): > > cf1 = SQLFORM( db.CONTACTS ) > > if cf1.accepts(request.vars,session): > > response.flash="Contact added." > > return dict( form=cf1 ) > > > The natural thing seemed to be to try: > > cf1 = SQLFORM( db.CONTACTS, db.EMAIL_ADDRESSES ) > > but that barfed, so next I tried... > > cf1 = SQLFORM( db.CONTACTS, db.EMAIL_ADDRESSES, fields= > > ["contact_name","email_address"]) > > which barfs also. I also tried... > > cf1 = SQLFORM( db.CONTACTS.id==db.EMAIL_ADDRESSES.contact_id, > > fields="contact_name" ) > > with the same result. > > > Am I missing something small or am I going about it entirely the wrong > > way? > > > Thanks, > > > Roger. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

