Client Side Validation In Openerp
I am still learning Openerp and please bear it if I asked something very simple. My issue is that I need to get validate two fields which represent start_time and end_time. both fi
Solution 1:
You should add an on_change function to your python code where you check if start_time and end_time is in the correct format. And in your xml you'll have to tell that the method should be called when the field changes.
XML
<fieldname="start_time"on_change="check_hour_format(start_time)"/><fieldname="end_time"on_change="check_hour_format(end_time)"/>
Python
the result should be something like
defcheck_hour_format(self,cr,uid,ids,time_field,context=None):
if correct formatreturn {}
else:
warning = {'title' : _("Warning for this value!"),
'message': _("Field not in correct format!"),
}
return {'warning': warning}
This code should work for this issue
import time
defcheck_hour_format(self,cr,uid,ids,time_field,context=None):
try:
time.strptime(char_input, "%H:%M")
return {}
except ValueError:
warning = {'title' : _("Warning for this value!"),
'message': _("Field not in correct format!"),
}
return {'warning': warning}
In on_change method, you can change field value
defon_change(self, cr, uid, ids, context=None):
# do somethingreturn {'value': { 'field_name': newValue},
'warning': {'title': _("Warning"),
'message': _("warning message")
}
}
Post a Comment for "Client Side Validation In Openerp"