تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2795 أدوات العرض

Does anyone know how to automatically convert Japanese full width number ex. [ 2], be automatically converted into half width number  [ 2 ] when inputted in an integer field?

Right now, full width number will be regarded  as  text  and  show  that  the  field  has  an  invalid  input. What I want is to automatically convert the inputted number and proceed with normal saving process.


الصورة الرمزية
إهمال
الكاتب

I was able to figure out by extending FieldInteger of basic_fields. If by any chance this could be made better, I would love to hear your suggestions, if any.

FieldInteger.include({
/**
* @override
* @returns {string} the content of the input
*/
_getValue: function () {
return this.$input.val();
},
/**
* Trim the value input by the user.
*
* @override
* @private
* @param {any} value
* @param {Object} [options]
*/
_setValue: function (value, options) {
value = this._convertToHalfWidth(value.trim());
return this._super(value, options);
},
_convertToHalfWidth: function(str) {
return str.replace(/[!-~]/g, r => String.fromCharCode(r.charCodeAt(0) - 0xFEE0));
},
})

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يونيو 25
1181
0
مايو 25
12
V17 Tree, Form view تم الحل
1
مارس 25
774
2
يناير 25
2758
1
ديسمبر 24
6412