Hey Ron,

This looks like an architectural issue to me.

You have to maintain state somehow for the form2 vars.

You can either do this via javascript on the client side, then have only 
one form server side, which has a dynamic set of fields.

If i were to do it this way, I would use a javascript library similar 
to https://github.com/marioizquierdo/jquery.serializeJSON

I have used this in the past, and then set up the controller much more 
simply to handle storing and retrieving JSON.

If you need to do row by row processing, you can filter out the JSON and 
store it in rows server side,

Otherwise, you can store it server side, let me know if you want to chat 
about this offline.

-Mark

On Friday, May 27, 2016 at 2:22:16 PM UTC-7, Ron Chatterjee wrote:
>
> Running into some issues and hoping community help out with thoughts. How 
> do I append to list:string and using form inside a form (custom form). 
>
> Question: How do I append skill_and_experience  as a list:string into the 
> field added_term as 'English': '1 year', 'Math':'2 years',...etc. 
>
> May be there is a better way to do this, but this is how I started out 
> with. 
>
>
> *Model.py:*
>
> db.define_table( 'Experience',Field('Experience_level'), format = 
> '%(Experience_level)s')
> db.define_table( 'teaching',Field('teach_string'), format = 
> '%(teach_string)s')
>
>
> db.define_table( 'add_list_item',
>                 Field('skill_list', db.teaching, label='Enter Your Skills 
> sets', comment = 'Enter skills'),
>                 Field('Experience_list', db.Experience, label='Enter Your 
> Experience',  comment = 'Enter years'))
>                 
>
> db.define_table( 'Project', 
>                 Field("Title", "string", 
> requires=IS_NOT_EMPTY(),default=None),
>                 Field("added_term", "list:string", 
> requires=IS_NOT_EMPTY()),)
>
>
>
> *Controller:*
> def create_table():
>     a_list = 'My skills and experience:'
>     skill_and_experience = [];
>  
>     form1 = SQLFORM(db.Project)
>     form2 = SQLFORM(db.add_list_item, submit_button=' + Add',).process()
>     form2.element('input[type=submit]').update(_class='btn btn-custom')
>     
>     if form2.accepted:
>         a = db(db.add_list_item.id == form2.vars.id).select().first()
>         skills = db(db.teaching.id == a.skill_list).select().first()
>         experience = db(db.Experience.id == 
> a.Experience_list).select().first()
>         skill_and_experience = skills.teach_string+':' +''+ 
> experience.Experience_level
>         added_term.append(skill_and_experience)
>         response.flash = T("Added Experience")
>     
>     if form1.accepted:
>         response.flash = T("success!")
>         
>     return dict(form1 = form1, form2 = form2, a_list = a_list)
>
>
> *View:*
>
> {{extend 'layout.html'}}
>
> <center>
>
> {{=form1.custom.begin}}
>
>
> <div class="input-title">
>     {{=form1.custom.widget.Title}}
>      <br>
>     
> {{=form2.custom.begin}}    
>
> <h4>{{=a_list}}</h4>
>
>
>
> <table>
> <thead>
>   <tr>
>      <div class="skill_list"> 
>  
>   <td> {{=form2.custom.widget.skill_list}}   </td>
>           <div class="exp_list"> 
>     <td>{{=form2.custom.widget.Experience_list}}   </td>    
>               
>                 <div class="add_button"> 
>               <td> {{=form2.custom.submit}} </td>   
>       
> </tr>
> </thead>
> </table> 
> <br>
> <br>
> {{=form2.custom.end}}
>       
>  {{=form1.custom.submit}}
>     
>     
>         </div> 
>       </div>
>       </div>  
>    </div> 
> {{=form1.custom.end}}
> </center>
>
> <style>
> .input-title{
>     height: 100px;
>     width: 400px;
> }
>
> #add_list_item_skill_list{
>      width: 200px;
> } 
> #add_list_item_Experience_list{
>      width: 200px;
> } 
>
>
> .btn-custom { text-align:right;color: blue;width:50px; 
> padding:20%;position: relative;top: -4px;left: 4px;height 20px;}   
> </style>
>
>
>
> The idea is to basically add experience and training using form2 and add 
> that to form1 and then process both. But I am having problem in appending 
> data into list:string like I would for project. 
>
> Project.id 
> <http://127.0.0.1:8000/test_two/appadmin/select/db?orderby=Project2.id>
> Project.Title2 
> <http://127.0.0.1:8000/test_two/appadmin/select/db?orderby=Project2.Title2>
> Project.added_term2 
> <http://127.0.0.1:8000/test_two/appadmin/select/db?orderby=Project2.added_term2>
> 1 <http://127.0.0.1:8000/test_two/appadmin/update/db/Project2/1> test1 
> test1
> 2 <http://127.0.0.1:8000/test_two/appadmin/update/db/Project2/2> test2 test1, 
> test2, test3
> 3 <http://127.0.0.1:8000/test_two/appadmin/update/db/Project2/3> test3 
> test23, 
> test32
>

-- 
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.

Reply via email to