The app I had attached in the preceding email works, but it broke the
workflow. I can't get the added inputs values in form.vars, so I take them
from request.vars or somewhere else don't remember...

There is also an other problem with this hack... It not uses de validators
for all the inputs... So as long as there is one filled input the form
submit and the other added inputs will let pass empty value or if you prefer
NULL will be inserted.

But at least you will be able to add all the field you want no matter how
many field the subform contain... Remove the added field you no more want if
you add to much inputs.

Submit and the data will be all linked or related to the id of the record of
the "master" table or the base table form.

 The jQuery script has to be edited by hand for each subform (or subtable
you use). If you modify your subtable (add a field) you will have to go
change the jQuery script... I just tried to make a proof of concept and see
what were the limits... So nothing fancy with the code. There is also a
couple of jQuery lines that were not working properly in this version I
think.

Ha yeah there is an other issue on read or update... There is no way to make
it works with crud.read or crud.update (I did not try anything about that
when I realize I broked the workflow).

Also, there is no way to make SQLFORM.factory works on update or read (edit
your linked data)... At least there is no easy already available way. You
have to crud.update on subtable and master table independantly to make any
change after the first seizure.

I did not have time last week to continue to work on that.

I identified differents alternatives that I did not explored in details yet
:

1) There is a "lib" in django for doing exactly that. I don't know django,
but the basic (tutorial 1, 2, 3, 4).

2) There is also Pyjamas that could be use into web2py... It seems to me the
most cumbersome alternative, since I have to learn many differents things.

3) WTForms... I also have to learn a lot to figure out if it could work with
web2py or if it has to be stand alone. If it needs work separately I actualy
think to explore if a loosely coupled framework could be more reliable for
my needs (Flask, WTForms, WSGI, jinja...)

That where I am...

I appreciate any help to push further the reflexion or build something...

Richard


On Wed, Feb 2, 2011 at 6:45 PM, skwasha <sas...@umich.edu> wrote:

> I'm curious if you ever got this all figured out? I wanna do something
> similar (allow users to create lists of things of arbitrary list
> length.) I'm new to web2py myself, so if you had something working
> you'd be willing to share it'd be of great interest/help.
>
> thanx
>
> On Jan 24, 11:27 am, Richard Vézina <ml.richard.vez...@gmail.com>
> wrote:
> > Found this :
> >
> > http://code.google.com/p/django-dynamic-formset/
> >
> > <http://code.google.com/p/django-dynamic-formset/>Richard
> >
> > On Fri, Jan 21, 2011 at 3:34 PM, Richard Vézina <
> ml.richard.vez...@gmail.com
> >
> >
> >
> > > wrote:
> > > Hello,
> >
> > > Here a version 0.00001 pre pre before alpha [?]
> > > (see attachement)
> >
> > > But it works...
> >
> > > There is code in :
> >
> > > layout.html in head : js that I move there to get debug web2py button
> (no
> > > view)
> > > default controller : register_new function and a couple of other
> functions
> >
> > > default/register_new
> >
> > > Add row button add all the rows you want. Fill it up submit... Go admin
> > > db.address see that there is a row for each added input for street and
> city.
> >
> > > Didn't test it to much.
> >
> > > I had to use request.vars to get street2, city2, etc. inputs that were
> > > filtered by .accept()
> >
> > > Validators not working for the added inputs... If one input is fill for
> > > required field it will pass and null will be entered in db.address for
> empty
> > > input.
> >
> > > Richard
> >
> > > On Wed, Jan 19, 2011 at 10:21 AM, Richard Vézina <
> > > ml.richard.vez...@gmail.com> wrote:
> >
> > >> If you move the script into the layout.html in the head it still
> works...
> > >> You can then remove the view /view/default/register.html_
> >
> > >> So you get access to admin, request, session, response button to see
> what
> > >> going. You can see that city2 vars is store in session for example.
> >
> > >> Richard
> >
> > >> On Wed, Jan 19, 2011 at 10:17 AM, Richard Vézina <
> > >> ml.richard.vez...@gmail.com> wrote:
> >
> > >>> For now only adding and removing city input. I clone city input retag
> > >>> id='city' to id='city2' for the first clone and so on. I change all
> the id
> > >>> attribute of other tag cloned like divs. I had a garbage can icon and
> make
> > >>> it mouseover. That it for now.
> >
> > >>> Since I change the id of input to city2, city3 all those cloned input
> are
> > >>> not consider by the register controller for now. I have to figure out
> how
> > >>> _filter_fields works to modifying it (add regex hope it will work).
> Then I
> > >>> would like the controller to add as many rows in the "subform" or
> table2
> > >>> (address table) as there is cloned city input fields.
> >
> > >>> If I am not changing the id of input it will not be w3c html
> compliant,
> > >>> but web2py will insert all the added input filled into city field of
> address
> > >>> table like this :
> >
> > >>> |city1|city2|city3|etc|
> >
> > >>> Not bad but not normalized schema and possibly problematic if length
> of
> > >>> city field is fixed or using to much space for nothing.
> >
> > >>> If you feel that you know how to modify register function I will be
> glad
> > >>> for your help.
> >
> > >>> When it read, we could had a new recipe into the book ;-)
> >
> > >>> Richard
> >
> > >>> On Wed, Jan 19, 2011 at 9:48 AM, mart <msenecal...@gmail.com> wrote:
> >
> > >>>> Excellent! je prends le train, direction MTL, a tous les quelques
> mois
> > >>>> pour me rendre au bureau (peut-etre un peu moins souvent l'hiver ;)
> )
> >
> > >>>> SO, I have a question: Once, I use the button to add a field (which
> > >>>> does work well), what should be the expected back-end result? does
> one
> > >>>> of the tables get updated? or should a new table get generated based
> > >>>> on input type? How about a Field name? generic one name fits all (or
> > >>>> depends on type?)
> >
> > >>>> Mart :)
> >
> > >>>> On Jan 19, 9:12 am, Richard Vézina <ml.richard.vez...@gmail.com>
> > >>>> wrote:
> > >>>> > ;-) Originellement oui...
> >
> > >>>> > I would tell you on the orther thread that I post this one... I
> will
> > >>>> do it
> > >>>> > just for the one that fall on the orther thread so they could keep
> > >>>> track...
> >
> > >>>> > I continue today working on this.
> >
> > >>>> > Richard
> >
> > >>>> > On Wed, Jan 19, 2011 at 12:30 AM, mart <msenecal...@gmail.com>
> wrote:
> > >>>> > > Hey, es-tu de Montreal?
> >
> > >>>> > > On Jan 18, 7:08 pm, Richard Vézina <ml.richard.vez...@gmail.com
> >
> > >>>> > > wrote:
> > >>>> > > > I forgot to paste :
> >
> > >>>> > > > def register():
> > >>>> > > >     form=SQLFORM.factory(db.client, db.address, formstyle =
> > >>>> 'divs') #,
> > >>>> > > > table_name='dummy_name')
> > >>>> > > >     if form.accepts(request.vars):
> > >>>> > > >         id =
> > >>>> db.client.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)
> >
> > >>>> > > > What to do for what in red?
> >
> > >>>> > > > I think _filter_fields is the key of the problem...
> >
> > >>>> > > > I didn't have a look to it actually...
> >
> > >>>> > > > Richard
> >
> > >>>> > > > On Tue, Jan 18, 2011 at 7:00 PM, Richard Vézina <
> > >>>> > > ml.richard.vez...@gmail.com
> >
> > >>>> > > > > wrote:
> > >>>> > > > > Hello Massimo,
> >
> > >>>> > > > > I am trying to insert data in 2 tables from one form... I
> would
> > >>>> like to
> > >>>> > > be
> > >>>> > > > > able to insert any number of rows or records in the
> subtable.
> >
> > >>>> > > > > I build this test app (see attach)... All the work I did is
> > >>>> mostly in
> > >>>> > > > > /default/register.html where there is jQuery script that
> allow
> > >>>> adding
> > >>>> > > new
> > >>>> > > > > city input and delete new city input...
> >
> > >>>> > > > > I built it from scratch for Web2py inspired by :
> >
> > >>>>
> http://charlie.griefer.com/blog/index.cfm/2009/9/17/jQuery--Dynamical.
> > >>>> > > ..
> >
> > >>>> > > > > What should I do in register to allow the function to insert
> all
> > >>>> the
> > >>>> > > filled
> > >>>> > > > > city clone field??
> >
> > >>>> > > > > Next step will be adapted my script that it manage all the
> > >>>> subform
> > >>>> > > columns
> > >>>> > > > > instead of only one.
> >
> > >>>> > > > > Thanks.
> >
> > >>>> > > > > Richard
> >
> >  330.gif
> > < 1KViewDownload

Reply via email to