Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
13192 Lượt xem

Is there a way to set the text displayed in each state for a boolean button?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

not in the default code... but you can extend the widget your self...

by default:

    active: Active/Inactive

    archive: Active/Archive

    prod_environment: Product/Test

    by default : On/Off

via the option "terminology"

<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>




UPDATE:

 Here a sample of code to do it... https://github.com/odoo-dev/odoo/commit/e43ec89ec5e6a4e2cc43bad31e3452f130210acb

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you. This is great. Looks perfect. I will try it out ASAP.

Tác giả

Hi, I'm having a bit of difficulty using your example.

My code is:

odoo.define("custom_boolean_button.FieldBooleanButton", function (require) {

"use strict";

var form_widgets = require("web.form_widgets");

form_widgets.FieldBooleanButton.include({

init: function() {

this._super.apply(this, arguments);

switch (this.options["terminology"]) {

case "active":

this.string_true = _t("Active");

this.hover_true = _t("Deactivate");

this.string_false = _t("Inactive");

this.hover_false = _t("Activate");

break;

case "archive":

this.string_true = _t("Not Archived");

this.hover_true = _t("Archive");

this.string_false = _t("Archived");

this.hover_false = _t("Unarchive");

break;

case "custom":

if (this.options["terminology_values"]) {

var terms = this.options["terminology_values"];

this.string_true = _t(terms.string_true); this.hover_true = _t(terms.hover_true);

this.string_false = _t(terms.string_false);

this.hover_false = _t(terms.hover_false);

break;

}

default:

this.string_true = _t("On");

this.hover_true = _t("Switch Off");

this.string_false = _t("Off");

this.hover_false = _t("Switch On");

}

},

});

});

I get the error:

TypeError: Cannot read property 'include' of undefined

Câu trả lời hay nhất

You can simply add the options 

options="{'terminology':{

                'string_true': 'verify',

                'hover_true': 'verify',

                'string_false': 'Unverify',

                'hover_false': 'Unverify'

             }}"

Then It will display Verify/Unverify on button.

Eg.

<button name="toggle_verify" type="object" class="oe_stat_button test" icon="fa-check">

                      <field name="verify" widget="boolean_button" options="{'terminology':{

                'string_true': 'verify',

                'hover_true': 'verify',

                'string_false': 'Unverify',

                'hover_false': 'Unverify'

             }}"/>

                  </button>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I used the solution provided by Jeremy and would just like to add that the terminology does not work if you have the field as a checkbox in the same view. The button will just display the checkbox. Remove the checkbox from the view and it works.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
<field name="your_boolean_field" nolabel="1"/>
<label attrs="{'invisible':[('your_boolean_field', '=', False)]}">
     Checked
</label>

<label attrs="{'invisible':[('Your_boolean_field','=',True)]}">

    Not Checked

</label>

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks for the reply. I'm sorry if I wasn't clear enough in my post. I'm actually looking for a way to change the strings displayed by the boolean_button widget. It has to be the widget because I'm using it to trigger a call to reload_on_button. I appreciate your reply, which would be otherwise totally workable.

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 23
3141
2
thg 4 19
10092
1
thg 5 19
6974
0
thg 10 16
18524
1
thg 1 24
14252