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: