hi Timmie, I'm also very interested in a simple way to use that pattern (either select from list or create new). Have you made any progress in the last few days?
Richard On May 26, 6:33 pm, Timmie <timmichel...@gmx-topmail.de> wrote: > > you can do > > > class OptionsWidget: > > > @staticmethod > > def has_options(field): > > return hasattr(field.requires, 'options')\ > > or isinstance(field.requires, IS_NULL_OR)\ > > and hasattr(field.requires.other, 'options') > > > @staticmethod > > def widget(field, value): > > id = '%s_%s' % (field._tablename, field.name) > > if isinstance(field.requires, IS_NULL_OR)\ > > and hasattr(field.requires.other, 'options'): > > opts = [OPTION(_value='')] > > options = field.requires[1].other.options() > > elif hasattr(field.requires, 'options'): > > opts = [] > > options = field.requires.options() > > else: > > raise SyntaxError, 'widget cannot determine options of %s' > > % field > > opts += [OPTION(v, _value=k) for (k, v) in options] > > returnSELECT(*opts, **dict(_id=id, _class=field.type, > > _name=field.name, value=value, > > requires=field.requires)) > > > db.mytest.person.widget=OptionWidget.widget > > Thanks for this example code. > > As it works not out of the box with my table, I would need to play a > bit with it. > > I think this is a faily common thing: > For instance these forms: > "where did you hear from us?": > Search engine, friends, newspaper, others => please > specifyhttp://support.easywebstore.net/index.php?_m=knowledgebase&_a=viewart... > > What about a workaroud to place a field in col3 when a user selects > "other" or "EnterNewItem" where the input can be typed in? > > Pseudocode: > <select> > <option value="volvo">Volvo</option> > <option value="saab">Saab</option> > <option value="mercedes">Mercedes</option> > <option value="new_value">EnterNewItem</option> => specify: > <input>mynewcar</input> > </select> > > The problem is how to sync these two forms. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---