Odoo Help

1

Masked input in text field OpenERP7

By
Sam
on 12/17/13, 11:35 AM 3,422 views

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

2
Grover Menacho
On 12/17/13, 12:03 PM

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.

Felipe
on 12/17/13, 8:03 PM

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

Sam
on 12/18/13, 6:20 AM

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?

Sam
on 12/19/13, 9:33 AM

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

GH Mediacloud, Grover Menacho
on 12/19/13, 12:31 PM
2
Mickaël Nadeau
On 12/17/13, 11:56 AM

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

0
Sam
On 12/19/13, 9:35 AM

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
0
Ray Carnes
On 12/19/13, 12:49 PM

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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 12/17/13, 11:35 AM
Seen: 3422 times
Last updated: 3/16/15, 8:10 AM