This question has been flagged
5 Replies
11631 Views

Hi,

How to force uppercase fields Char ? odoo 10

Regards,

Avatar
Discard
Best Answer

Hi,

Just do one thing, in the onchange of that field,

@api.onchange('field_name')
def set_upper(self):
    self.field_name = str(self.field_name).upper()
    return


Thanks

Avatar
Discard

Firstly, make sure you do a check if it is set:

self.field_name = str(self.field_name).upper() of self.field_name else ''

Without that it will set the field to "FALSE" if you delete the data in it.

If this field is set by an internal function the onchange won't be called, so if there's any reason this field will be edited by another function this is unsafe.

Author

Yeah it set empty field by FALSE so i'm try to add your code but it give me an error

Best Answer
Esto te puede servir.
<field name="nombre" class="o_required_modifier" placeholder="Ex. Juan Mejia"/>nombre = fields.Char('Nombre', required=True)
@api.onchange('nombre')    
def solo_mayusculas(self):        
if self.nombre:                
 self.nombre = str(self.nombre).upper()       
else:           
 self.nombre = '' 
Avatar
Discard
Best Answer

Hi

There's no default setting for this, to have it done properly you would need to hook the write method or make a widget.

A workaround is to add the following to the field definition in the view:

 style="text-transform: uppercase;"

This will change the rendering of the field to be uppercase, but it will still be stored as lowercase, so if you show it in another view without this style it will still be in lowercase.

Regards,
Jake Robinson
Dionysus Software

Avatar
Discard