I read in the book chap 07 at Onvalidation... Additionnal checks on the form
and eventually add errors to the form... I could maybe use onvalidation to
get my jQuery added fields, checks for errors base on validator and pass the
added input to form.vars.

Richard

On Tue, Jan 25, 2011 at 12:11 PM, Richard Vézina <
[email protected]> wrote:

> You still can enter only one related item (record) at a time in the
> combined tables form... How can you add the many differents address of one
> client in address table in one time to have a normalized schema?
>
> There is also a 3 (4 in case you want to store the type of phone you have :
> Home, mobile, etc.) tables needed in case you want to store phone number for
> example :
>
> Client
> Address
> Phone
> PhoneType
>
> AddressType could be also interresting...
>
> Richard
>
>
> On Fri, Jan 21, 2011 at 11:50 PM, mart <[email protected]> wrote:
>
>> I have a question: When we say '2 forms', I immediately think 2 forms,
>> in the sense that both forms are used at times separately, and at
>> other times, combined. When I think of subforms, I think of either 1
>> of 2 things: 1) it wouldn't make any sense to have that form stad on
>> its own (it may be useful in many situations, but never alone. 2) the
>> subform can go both ways, on its own (requires contexte) and as a
>> another form's subform (avoids duplication). So, I'm trying to
>> understad the language used here and t see if I am possibly not doing
>> something correctly. my take is (and this is where I get "iffy" about
>> combining forms vs combining tables. It seems to me that the meat in
>> in the tables where the forms are just there to capture data. That
>> said, what is the main advantage with combining forms over combining
>> tables?
>>
>> Is there any disadvantage to collecting related data to populate a
>> tables different tables, even if it includes many of those single
>> value tables (like table category), and building the form by
>> collecting pertinent tables to create the single, stands-on-its-own
>> form? and kind of goes to the :audit trail slice. for one particular
>> app (a requests app),  instead of thinking of combining forms to
>> create a unique request, I isolated items that could potentially be of
>> value in more than 1 situation. I used the "audit trail" slice's
>> technique to achieve this. In the end depending on how and which
>> tables I combine, I can create unique forms with specific use if the
>> combined data. I treat the forms like recipes (table noodle goes to
>> combined_table_spaghetti, or to combined_table_soup, etc,,, would even
>> go to combined_table_Arts_And_Krafts if noodles were used. If I were
>> missing a table glue, I would have something (a button or something)
>> to create a table instead of a row.
>>
>> example:
>>
>> table_a is common to al request (general info)
>> table_b can be source code specific
>> table_c can IMEI specific
>> table_d can info about the dev cert
>> table_e can be a a table with a single field (like yes/no thing)
>>
>> table_a + table_b = build request form
>> table_a + table_c = IMEI number request form
>> table_a + table_c + table_d = dev cert request form
>>
>> then all I need is to create a dev cert request form is this and throw
>> a form on it:
>> db.define_table('dev_cert_request',
>>                 table_a,
>>                 table_c,
>>                 table_d,
>>                 table_e,
>>          Field('have_device_already', 'boolean'))
>>
>> So the question: is there and advantage to working with the forms as
>> opposed to working with the tables? working with tables seems more
>> flexible and intuitive and is a time saver (re-using existing tables),
>> but maybe I have the wrong approach regardless and trouble is waiting
>> for me at some point?
>>
>> Thanks
>> Mart :)
>>
>>
>>
>> On Jan 21, 4:39 pm,
>> Lennon <[email protected]> wrote:
>> > Oh I see.  The validation does at least seem to be working on the
>> > second form.  It won't let me enter values not specified in the model.
>> >
>> > If I am to use SQLFORM factory, how do I do an update/delete?
>> >
>> > Kenneth said:
>> >
>> > "As I understand the only option is to use factory, if you wan t to
>> > update you have to create a form with factory then fill all fields
>> > with
>> > db.t_table.f_field.value = something"
>> >
>> > But I'm not exactly sure how to fill the fields in with that method.
>> > Could somebody give me an example in the following context?:
>> >
>> > def test_add_user():
>> >     form=SQLFORM.factory(db.user,db.address)
>> >     if form.accepts(request.vars):
>> >         id = db.user.insert(**db.client._filter_fields(form.vars))
>> >         form.vars.client=id
>> >         id = db.address.insert(**db.address._filter_fields(form.vars))
>> >         response.flash='Thanks for filling the form'
>> >     return dict(form=form)
>> >
>> > On Jan 21, 4:22 pm, DenesL <[email protected]> wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > Doing form.append(SQLFORM(...)) creates invalid HTML since you can not
>> > > nest FORMs, but your browser is saving the day by ignoring the nested
>> > > form and including its fields only.
>> >
>> > > Moreover form.accepts only validates your db.user fields, and none of
>> > > db.address (unless they happen to be named the same).
>> >
>> > > You should be following what Bruno recommended:
>> http://web2pyslices.com/main/slices/take_slice/102
>> >
>> > > On Jan 21, 3:48 pm, Lennon <[email protected]> wrote:
>> >
>> > > > I solved my problem.  Since the form.vars were passing through to
>> the
>> > > > controller, I just simply did my own manual insert:
>> >
>> > > > def test_add_user():
>> >
>> > > >     form = SQLFORM(db['user'])
>> > > >     form.append(SQLFORM(db['address']))
>> >
>> > > >     #submit data
>> > > >     if form.accepts(request.vars):
>> >
>> > > >         #check whether the form had errors
>> > > >         if form.errors:
>> > > >             response.flash = 'Form has errors'
>> > > >             return dict(form=form)
>> > > >         else:
>> >
>> > > > db.address.insert(user_id=form.vars.id,address=form.vars.address)
>> > > >             session.flash = "User Added"
>> > > >             redirect(URL('admin', 'test_add_user'))
>> >
>> > > >     #return the view
>> > > >     return dict(form=form)
>> >
>> > > > Now all I have to do is remove the first submit button.
>> >
>> > > > On Jan 21, 2:30 pm, Lennon <[email protected]> wrote:
>> >
>> > > > > I have two reasons for not wanting to use SQLFORM factory.  First,
>> I
>> > > > > can't figure out or find how to use SQLFORM factory as an update/
>> > > > > delete form when combining multiple table (although I'd love to
>> see
>> > > > > how if it can be done).  Second, I will be wanting to do some
>> really
>> > > > > complicated forms in the future and would like to understand how
>> to
>> > > > > combine SQLforms.
>> >
>> > > > > With the insert form code listed below, I've been able to combine
>> the
>> > > > > two forms on one page.  They both render (with two submit buttons)
>> and
>> > > > > the form validation works for both of them regardless of which
>> submit
>> > > > > button I hit (which made me think I had successfully combined
>> them).
>> >
>> > > > > But when the form accepts the data, it only does an insert on the
>> > > > > original form and doesn't work on the appended form.
>> >
>> > > > > When I run in debug mode I see that FORM.vars correctly has
>> captured
>> > > > > all of the values for both forms.  But FORM.table and FORM.fields
>> both
>> > > > > only have the values for the first SQLFORM.
>> >
>> > > > > Thanks for any help you can give me.
>> >
>> > > > > def test_add_user():
>> >
>> > > > >     form = SQLFORM(db['user'])
>> > > > >     form.insert(len(form),SQLFORM(db['address']))
>> >
>> > > > >     #submit data
>> > > > >     if form.accepts(request.vars):
>> >
>> > > > >         #check whether the form had errors
>> > > > >         if form.errors:
>> > > > >             response.flash = 'Form has errors'
>> > > > >             return dict(form=form)
>> > > > >         else:
>> >
>> > > > >             session.flash = "User Added"
>> > > > >             redirect(URL('admin', 'test_add_user'))
>> >
>> > > > >     #return the view
>> > > > >     return dict(form=form)
>>
>
>

Reply via email to