I know that the tag 'size' sets the maximum size of values stored for a field.
For example, in such way:
name_of_field = fields.Char('name of field', size=2)
I could write a maximum of two characters for 'name_of_field': one or two characters are allowed.
How can I prevent to write only one character?
-----------------------------------
This is the right xml file:
<field name="scode" on_change="on_change_length_id(scode)"/>
and this is the right .py file:
# -*- encoding: utf-8 -*-
from openerp import models, fields
from openerp.osv import osv
class myclass(models.Model):
_name = 'tbl
_description = 'Write into db'
scode= fields.Char('Code', size=3 required=True)
def get_lenght(self, cr, uid, ids, scode, context=None):
if scode and len(scode) != 3:
My_error_Msg = 'Wrong size'
raise osv.except_osv(("Warning!"), (My_error_Msg))
return
else:
return scode
def on_change_length_id(self, cr, uid, ids, scode, context=None):
res = {'value': {'scode': self.get_lenght(cr, uid, ids, scode, context=context)}}
return res