On Thursday, August 14, 2014 6:16:02 PM UTC-4, Dragan Matic wrote:
>
> I have a form with two fields, one field is a selection box of previously 
> typed values and the other is a text box. User can choose a value from a 
> selection box or can type a value in text box and submit it in which case I 
> would like to add a value to a selection box, something like this:
>
>
> # some code that reads values from db into dictionary_of_typed_values
>
> #  create a form
>     form=SQLFORM.factory(
>         Field('field1', requires=IS_EMPTY_OR(IS_IN_SET(
> dictionary_of_typed_values))), 
>         Field('field2', 'string'))
>
>     if form.accepts(request, session):    
>             # insert new value into db             
>             new_value_id = db.table.insert(column1=form.vars.field1, 
> column2=form.vars.field2)
>
>             if form.vars.field1 == None:
>                 # here I would like to add form.vars.field2 to set of 
> values in field1                
>
>     return dict(form=form)
>
>
You can try something like:

    if form.vars.field1 == None:
        form.custom.widget.field1.append(OPTION(form.vars.field2, _value=
new_value_id))

Note, that will simply append the new option to the list of options. If you 
need it to be inserted at a particular location in the list, the code will 
get a little more complicated.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to