I think you can't use compute since you modify a field where the user as to
enter something base on the len of user input, so I think you should
transform the code below into function and use onvalidation=function

x=len(form.vars.description)
if x>128:
    i=128
    dots="..."
else:
    i=x-1
    dots=""
s=form.vars.description[0:i] + dots

Richard




On Fri, Apr 20, 2012 at 11:26 AM, Annet <[email protected]> wrote:

> I defined a table eventList:
>
> db.define_table('EventList',
>    ...
>     Field('description',type='text'),
>     Field('shortdescr',length=128,writable=False,readable=False),
>     ....
>     migrate=False)
>
> db.EventList.description.requires=IS_LENGTH(1536,error_message='length
> exceeds 1536 characters')
> db.EventList.shortdescr.requires=IS_LENGTH(128,error_message='length
> exceeds 128 characters')
>
> shortdescr should be the first 128 characters of description followed by
> three dots. In a function this works:
>
> x=len(form.vars.description)
> if x>128:
>     i=128
>     dots="..."
> else:
>     i=x-1
>     dots=""
> s=form.vars.description[0:i] + dots
>
> ... but I'd like to add it to the model file. I had a look at the compute
> option but wasn't able to figure out how to get it syntactically correct.
>
>
> Kind regards,
>
> Annet.
>

Reply via email to