char字段聚焦全选功能已完成

This commit is contained in:
mgw
2023-08-11 12:22:59 +08:00
parent fc490f1612
commit 68805fee4a
3 changed files with 166 additions and 1 deletions

View File

@@ -10,7 +10,7 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
'depends': ['stock','web' ],
'depends': ['stock', 'web', ],
'data': [
# 'security/group_security.xml',
# 'security/ir.model.access.csv',

View File

@@ -0,0 +1,84 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { CharField } from '@web/views/fields/char/char_field';
// 继承CharField组件实现自定义组件:当光标聚焦于输入框时,选中输入框内容
class CustomChar extends CharField {
/**
* @override
* @private
* @param {MouseEvent} ev
* @returns {Promise}
*/
onMounted() {
super.onMounted();
console.log('CustomChar.onMounted1');
// 当光标聚焦于输入框时,选中输入框内容
this.input.el.addEventListener('focus', function () {
this.select();
})
}
// setup() {
// console.log('CustomChar.setup1');
// alert('CustomChar.setup1');
// super.setup();
// console.log(this)
// console.log('this.input', typeof this.input.el)
// console.log('this.props', this.props)
// console.log('this.props', this.props['value'])
// console.log('this.instanse', this.instance)
// console.log('this.el', this.el)
// console.log('9999999999',this)
// // this.input.el.addEventListener('focus', function() {
// // console.log('1233333333333')
// // })
// }
//
// async willStart() {
// console.log('CustomChar.willStart1');
// alert('CustomChar.willStart1');
// await super.willStart();
// }
//
//
// mounted() {
// console.log('CustomChar.mounted1');
// // Now, the component's DOM element should be available
// const inputElement = this.el.querySelector('input');
// // if (inputElement) {
// // inputElement.addEventListener('focus', function() {
// // this.select();
// // });
// // }
// }
// setup() {
// console.log('CustomChar.setup1');
// alert('CustomChar.setup1');
// super.setup();
//
// // 查找输入元素
// const inputElement = this.el.querySelector('input');
// if (inputElement) {
// inputElement.addEventListener('focus', function() {
// this.select();
// });
// }
// }
// this.$input.on('focus', function () {
// $(this).select();
// });
// 当光标聚焦于输入框时,选中输入框内容
}
registry.category("fields").add("custom_char", CustomChar);

View File

@@ -0,0 +1,81 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { Many2OneField } from '@web/views/fields/many2one/many2one_field';
// 继承FieldMany2One组件实现自定义组件:当光标聚焦于输入框时,选中输入框内容
class CustomMany2One extends Many2OneField {
/**
* @override
* @private
* @param {MouseEvent} ev
* @returns {Promise}
*/
setup() {
console.log('CustomMany2One.setup11111111111111');
super.setup();
}
onMounted() {
console.log('CustomMany2One.onMounted1');
// 当光标聚焦于输入框时,选中输入框内容
this.input.el.addEventListener('focus', function () {
this.select();
})
}
}
registry.category("fields").add("custom_many2one", CustomMany2One);
// /** @odoo-module **/
//
// import { registry } from "@web/core/registry";
// // import { field_registry } from '@web/legacy/js/fields/field_registry';
// // import { FieldMany2One } from '@web/legacy/js/fields/relational_fields';
// import { Many2OneField } from '@web/views/fields/many2one/many2one_field';
//
//
// // 继承FieldMany2One组件实现自定义组件:当光标聚焦于输入框时,选中输入框内容
// class CustomMany2One extends Many2OneField {
// /**
// * @override
// * @private
// * @param {MouseEvent} ev
// * @returns {Promise}
// */
// setup() {
// console.log('CustomMany2One.setup11111111111111');
// super.setup();
// }
// onClick(ev) {
// super.onClick(ev);
// console.log('CustomMany2One._onInputClick');
//
// this.$input.select();
// }
//
// }
//
// // field_registry.add('custom_many2one', CustomMany2One);
// registry.category("fields").add("custom_many2one", CustomMany2One);
// const CustomMany2One = FieldMany2One.extend({
// /**
// * @override
// * @private
// * @param {MouseEvent} ev
// * @returns {Promise}
// */
// _onInputClick: function (ev) {
// console.log('CustomMany2One._onInputClick');
// this._super.apply(this, arguments);
// this.$input.select();
// }
// });
//
// field_registry.add('custom_many2one', CustomMany2One);
// export default CustomMany2One;