On Mon, Jul 2, 2012 at 2:08 PM, Santiago <[email protected]> wrote:
> Hello,
>
> I have a field defined as below :
>
> Field('id_indra', length=5, label=T('ID Indra'), notnull=False,
> requires=[REQUIRED, MAX_5, IS_MATCH(r'^[a-zA-Z0-9]{5}$')])
>
> Is it is possible to intercept all inserts / updates over this field and
> do a zfill() before the accion takes place? So, if the field is '5', they
> it would be completed with zeroes with a result of '00005' before insert /
> update.
>
> Thanks in advance
>
> Regards,
> Santiago
>
A way to achieve this would be on form submission with the onvalidation
argument, such as:
def myaction:
def pad_indra(form):
form.vars.id_indra = form.vars.id_indra.zfill(5)
form = SQLFORM(...)
if form.process(onvalidation=pad_indra).accepted:
...
If you use this in multiple form you could move pad_indra to the
'controller' scope to share it.
Miguel
HTH