演示: Boolean Button
上图中归档/有效转换按钮就是一个被称作布尔按钮的控件。这个控件对应一个布尔类型的字段,所以被称作布尔按钮。
我们可以用下面的语法来定义这个按钮:
<button name="toggle_active" type="object"
class="oe_stat_button" icon="fa-archive" groups="sales_team.group_sale_manager">
<field name="active" widget="boolean_button"
options='{"terminology": "archive"}'/>
</button>
其中options选项中的terminology所设定的值是这个按钮在不同状态下所显示的文字。
terminology所设定的值,默认有下面这几个:
-
active: Active/Inactive
-
archive: Active/Archive
-
prod_environment: Product/Test
-
by default : On/Off
当然我们也可以自定义不同状态下的显示文字,比如:
<button name="toggle_verify" type="object" class="oe_stat_button test" icon="fa-check">
<field name="verify" widget="boolean_button" options="{'terminology':{
'string_true': 'Verified',
'hover_true': 'Reset',
'string_false': 'Unverified',
'hover_false': 'Verify'
}}"/>
</button>
其中string_true所对应的值在字段值为True时显示,hover_true所对应的值在字段值为True时鼠标悬停所显示的文字。
其他依此类推。