How to preselect options in SELECT helper in web2p

2019-08-23 07:02发布

问题:

when creating multiple select input with SELECT, OPTION helpers, I want to preselect some options, I tried following

OPTION('myOption', _value=val, value=[v1, v2])

extrapolating from the docs, but it does not work

回答1:

"value" is an attribute of the "SELECT" helper.

From the documentation :

web2py make a distinction between "_value" (the value of the OPTION), and "value" (the current value of the enclosing select). If they are equal, the option is "selected".

http://www.web2py.com/books/default/chapter/29/05/the-views?search=OPTION%28

For example :

SELECT(
    OPTION('Option1', _value='1'),
    OPTION('Option2', _value='2')
    , value='2')

Will select "Option2" whereas

SELECT(
    OPTION('Option1', _value='1'),
    OPTION('Option2', _value='2')
    , value='2')

Will select "Option1"



标签: web2py