Odoo Help

Welcome!

This community 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.

1

Masked input in text field OpenERP7

By
Sam
on 12/17/13, 11:35 AM 2,593 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

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

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

Ray Carnes

--Ray Carnes--
15717
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

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

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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