How to preselect options in SELECT helper in web2py

ε祈祈猫儿з 提交于 2019-12-25 04:33:10

问题


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"



来源:https://stackoverflow.com/questions/19999852/how-to-preselect-options-in-select-helper-in-web2py

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!