Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
7933 มุมมอง

Is it possible to mask the input data into the text field in OpenERP7? In case I need to imput only digits or (if possible) event specify the imput format

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

password="True": replace field values by asterisks, "*".

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Not exactly, but with onchange you can be sure that users are not inserting wrong characters

I think that you don't want to use float or int and you are using char, so I did this:

import re
 def onchange_field_name(self, cr, uid, ids, field_name):
    if re.match("^-?[0-9]+$", field_name) != None:
        return True
    else:
        raise osv.except_osv('Error', 'Please insert a number')

It's only to validate fields, but you can use it on another way.

อวตาร
ละทิ้ง

Inside on-change methods you should use warnings, and in this case if there is a warning then also return a null value for that field.

ผู้เขียน

Yes, this works, thank you. But it is still a partial sollution (

ผู้เขียน

Need some more help if possible: Tried to modify the code so it would remove all the non-digits upon onchange event:

import re
def onchange_phone_number(self, cr, uid, ids, field_value):
    new_value = re.sub("[^0-9]", "", field_value)
    return {'value': {'my_field': new_value}}

But it falls out with the following error:

File "/usr/lib/python2.7/re.py", line 151, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer

Any ideas what is wrong with it?

Maybe you are not sending any field_value. Try with "if field_value:" and then remove non numeric values, otherwise return {}

ผู้เขียน คำตอบที่ดีที่สุด

Need some more help if possible: Tried to modify the code so it would remove all the non-digits upon onchange event:

import re
def onchange_phone_number(self, cr, uid, ids, field_value):
    new_value = re.sub("[^0-9]", "", field_value)
    return {'value': {'my_field': new_value}}

But it falls out with the following error:

File "/usr/lib/python2.7/re.py", line 151, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Mickael actually had the right answer:

For ANY field, just add the XML tag "password" to the definition.

<field name="password" password="True"/>

Then, any data typed into this field will show up as *****

https://doc.openerp.com/6.0/developer/2_6_views_events/views/design_element/

image description

อวตาร
ละทิ้ง