How about this? def ListStringWidget(field,value,**attributes): _id = '%s_%s' % (field._tablename, field.name) _class = isinstance(field.type,str) and field.type or None _name = field.name requires = field.requires items=[LI(INPUT(_id=_id,_class=_class,_name=_name,value=v)) for v in value or [''] if v.strip()] script=SCRIPT(""" // from http://refactormycode.com/codes/694-expanding-input-list-using-jquery (function(){$.fn.grow_input = function() { return this.each(function() { var ul = this;$(ul).find(":text").keypress(function (e) { return (e.which == ENTER_KEY) ? enter_press(ul) : true;}); }); }; var ENTER_KEY = 13; function enter_press(ul) { var new_line = make_line(ul); remove_empty_lines(ul); new_line.appendTo(ul); new_line.find(":text").focus(); return false; } function make_line(ul) { var line = $ (ul).find("li:first").clone(true); line.find(':text').val(''); return line; } function remove_empty_lines(ul) { $(ul).find("li").each(function() {var trimmed = jQuery.trim($(this.firstChild).val()); if (trimmed=='') { $(this).remove(); } else {$ (this.firstChild).val(trimmed); } }); } }) (); jQuery(document).ready(function(){jQuery('# %s_grow_input').grow_input();}); """ % _id) attributes['_id']=_id+'_grow_input' return TAG[''](UL(*items,**attributes),script)
db.define_table('person',Field('name'),Field('addresses','list:string',widget=ListStringWidget))