IS_NOT_EMPTY_OR(IS_IN_SET((),multiple=True))

69 views
Skip to first unread message

billmac...@gmail.com

unread,
May 8, 2016, 12:51:23 PM5/8/16
to web2py-users
I would like to have a set that requires to be not empty. But looking at the documentation there are no such thing as IS_NOT_EMPTY_OR like we have for  IS_EMPTY_OR. Any thoughts?

sesenmaister

unread,
May 9, 2016, 4:36:55 AM5/9/16
to web...@googlegroups.com
When using the validator IS_IN_SET(..)  , it will require the values are in the set. 

So it will require not to be empty.



You can define your custom validator classes, take a look at this example:
http://stackoverflow.com/questions/14724584/web2py-custom-validators

Anthony

unread,
May 9, 2016, 11:03:38 AM5/9/16
to web2py-users
First, note that IS_IN_SET requires an item in the set, so no need for IS_NOT_EMPTY with it. If you are using IS_IN_SET with multiple=True, then you are allowed to select zero items, but you can instead set multiple=(1, len(the_set)), and it will require at least one selection.

Also, even if the above were not the case, you wouldn't want IS_NOT_EMPTY_OR -- you would want something like IS_NOT_EMPTY_AND (i.e., you want the value to be non-empty and within your set). However, you can already do the latter by simply putting multiple validators in a list: [IS_NOT_EMPTY(), IS_IN_SET(...)].

Anthony

billmac...@gmail.com

unread,
May 9, 2016, 11:20:16 AM5/9/16
to web...@googlegroups.com
Thank you very much Anthony. Works like  you explained! You know one of the problem of using the set is when rendered in a view, it shows up as ['string']. And I believe others have asked the same questions in the forum before. How to delete these html tags because XML(string, sanitize...) doesn't really work. is there a magic routing that filters out any html tag and gives us semantic texts? Have you ever encountered this problem?
Reply all
Reply to author
Forward
0 new messages