Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
4 Ответы
7883 Представления

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

Аватар
Отменить