Setting a default value for a reference field

50 views
Skip to first unread message

mostwanted

unread,
Sep 18, 2020, 6:41:11 AM9/18/20
to web2py-users

Is there a way to create a placeholder for a reference field?
e.g:
{{
Field('place', 'reference locations', label=SPAN('Place of operations'), widget=lambda field, value: SQLFORM.widgets.reference.widget(field, value, _placeholder="Whats your place of operations?"))
}}

Regards;

Mostwanted

Jim S

unread,
Sep 18, 2020, 10:13:10 AM9/18/20
to web2py-users
Reading from this stackoverflow post, it appears it isn't something you can do.  But, they show some alternatives:


However, that post is pretty old, maybe someone else has some better solutions.

-Jim

Annet

unread,
Sep 19, 2020, 5:32:08 AM9/19/20
to web2py-users
I wonder why the IS_IN_DB() validator doesn't suit your needs.

I have a field day:

Field('day', 'reference cal_day', default=None, required=True, requires=IS_IN_DB(db, 'cal_day.id', '%(id)s %(name)s',  zero='Select a day'), ondelete='RESTRICT', notnull=True, label='Day *'),

Doesn't zero = 'Whats your place of operations?' do what you want?


Annet
Op vrijdag 18 september 2020 om 12:41:11 UTC+2 schreef mostwanted:

mostwanted

unread,
Sep 19, 2020, 10:54:36 PM9/19/20
to web2py-users
Thank you Annet
Reply all
Reply to author
Forward
0 new messages