[web2py] Help with forms and dynamic values

2013-04-23 Thread Amirshk
Hi,

I was wondering what would be the best approach for the following 
situation: 
I have a form that has some fixed input fields. In addition there are 
fields the use can add or remove dynamically.

Is there a way to do this using form or custom form, or do I need to write 
all the code myself.

Currently I wrote the form manually, but this means that I need to write 
all the validation and error display as well. Am I right?

Here is a snippet of an example code showing my use-case:

{{extend 'layout.html'}}



value1



value2



Add a Stop
 
value3


  






value_middle
Remove




$(document).ready(function(){
$('#add_station_btn').on('click',function(){
$('#middle_stations').append($('#middle_template').html());
var index=$('#middle_stations li:last').index();
 var newname=index+'_value_middle';
$('#value_middle').attr('id',newname);
$('#'+newname).attr('name',newname);
 var newname=index+'_remove_station_btn';
$('#remove_station_btn').attr('id',newname);
$('#'+newname).on('click', function() {
$(this).closest('li').remove();
});
});
});





Thanks

-- 

--- 
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/groups/opt_out.




[web2py] How to create a list from a select query

2012-11-05 Thread Amirshk
I am trying to figure out how to convert a Set or Rows into a list and not 
a table.
This is what I tried so far:

`list_tags` was supposed to convert the list, but I can't figure this one 
out. 

def list_tags(id):
tags = db(db.credit_transactions_tags.transaction_ref == 
id).select()
if tags:
html = ''
for tag in tags:
html += ''+tag.name+''
html += ''
return html
else:
return ''

links =  [{'header':'Tags', 'body': lambda row: list_tags(row.id) 
}]
records = 
SQLFORM.grid(db.credit_transactions.account_ref==account_id, fields=fields, 
links=links, maxtextlength=50, args=[account_id])


Thanks in advance.

--