Simply dropping this in does not appear to work, I am getting nothing
where the widget ought to be.

In any case, I don't think this is going to work for my case, as a
simply storing mutltiple strings in a single field isn't what I need.

I have another table with ~20 columns.. nutrition information
specifically.

Two types of things have nutrition information, recipes and basic foods.
Basic foods are simple

Name |  Type  |  Nutrition Table Ref

Recipes are quite a bit more complex, but also need to reference the
Nutrtion Table.

Maybe I am just structuring this wrong entirely and should keep the
Nutrition information in the two tables?  Since I will have to be
querying the Nutrition table to get both basic Foods and Recipes back, I
think it makes sense to keep the Nutrition information separate.

There is only a one to one correspondence between nutrition information
and another row.. the same row in the nutrition table won't be
referenced by two different rows in either the recipe table or the
basic_foods table.

I hope that this explanation makes clear why I believe your list:string
solution (which is great and I will use else where in this app) does not
solve this particular problem.

Thanks
Geoff

On Wed, 2010-09-08 at 12:46 -0700, mdipierro wrote:
> 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))
> 


Reply via email to