Is there a way to put icon or image picker in form?

55 views
Skip to first unread message

Dragan Matic

unread,
Jan 9, 2018, 7:33:07 AM1/9/18
to web2py-users
I would like to have an icon or image picker in form where user could choose from a set of predefined icons.
Form would contain a few other fields like a title, text and an icon that would visually mark the topic of the text. Icons could be either pictures in 'static' folder or in 'uploads' (site admin would preload a few icons in a table, something like 'text_topic_symbols' or something similar).

I've tried doing something like this:

db
.define_table('topic_icon',
   
Field('topic_icon_image', 'upload'))

db
.define_table('content',
   
Field('title', 'string', length=256, required=True),
   
Field('body', 'text', required=True),
   
Field('topic_type', 'reference topic_icon'))



But then I don'k know how to build a FORM that would show image picker.

Would it be possible to do with web2py or I have to use some javascript magic?

Richard Vézina

unread,
Jan 10, 2018, 2:05:43 PM1/10/18
to web2py-users
sqlform.factory() if you have 2 tables like now and SQLFORM() if you recude this 2 table into 1.

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tim.n...@conted.ox.ac.uk

unread,
Jan 11, 2018, 7:53:12 AM1/11/18
to web2py-users
If you want to avoid javascript magic, you'll want to create a custom widget, probably something extending a dropdown.  However, there are nice lightweight js libraries for adding images to dropdown options.
Reply all
Reply to author
Forward
0 new messages