[英]customise odoo12 JavaScript file
I want to replace the functionality of the js file.我想替换js文件的功能。 As we have widget many2many in relation_field.js in that there is one function search, that contains code for creating and edit option.由于我们在relation_field.js 中有小部件many2many,因为有一个函数搜索,其中包含用于创建和编辑选项的代码。 I want to change this functionality as per my needs.我想根据我的需要更改此功能。 Following is the main code that I want to change以下是我要更改的主要代码
if (create_enabled && !self.nodeOptions.no_create_edit) {
var createAndEditAction = function () {
// Clear the value in case the user clicks on discard
self.$('input').val('');
return self._searchCreatePopup("form", false, self._createContext(search_val));
};
values.push({
label: _t("Create and Edit..."),
action: createAndEditAction,
classname: 'o_m2o_dropdown_option',
});
} else if (values.length === 0) {
values.push({
label: _t("No results to show..."),
});
}
following is my code.以下是我的代码。 I want to add an alert function to create and edit the option of many2many fields.我想添加一个警报功能来创建和编辑 many2many 字段的选项。 For that, I have use alert function.为此,我使用了警报功能。
odoo.define('survey_inherit.create_record',function(require){
"use strict";
console.log("In js file");
var relationalField = require('web.relational_fields');
var FieldMany2One = relationalField.FieldMany2One.include({
_search: function (search_val) {
var create_enabled = self.can_create && !self.nodeOptions.no_create;
if (create_enabled && !self.nodeOptions.no_create_edit) {
var createAndEditAction = function () {
// Clear the value in case the user clicks on discard
self.$('input').val('');
**alert(‘Test’);**
//return self._searchCreatePopup("form", false, self._createContext(search_val));
};
this.values.push({
label: _t("Create and Edit..."),
action: createAndEditAction,
classname: 'o_m2o_dropdown_option',
});
} else if (this.values.length === 0) {
this.values.push({
label: _t("No results to show..."),
});
}
}
});
});
can any one please help or any other suggestion.任何人都可以帮忙或任何其他建议。 Thanks in advance.提前致谢。
I suggest you to remove assigning your code to FieldMany2One
variable.我建议您不要将代码分配给FieldMany2One
变量。
So code will be:所以代码将是:
odoo.define('survey_inherit.create_record',function(require){
"use strict";
console.log("In js file");
var relationalField = require('web.relational_fields');
relationalField.FieldMany2One.include({
_search: function (search_val) {
var create_enabled = self.can_create && !self.nodeOptions.no_create;
if (create_enabled && !self.nodeOptions.no_create_edit) {
var createAndEditAction = function () {
// Clear the value in case the user clicks on discard
self.$('input').val('');
**alert(‘Test’);**
//return self._searchCreatePopup("form", false, self._createContext(search_val));
};
this.values.push({
label: _t("Create and Edit..."),
action: createAndEditAction,
classname: 'o_m2o_dropdown_option',
});
} else if (this.values.length === 0) {
this.values.push({
label: _t("No results to show..."),
});
}
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.