On Tuesday, January 14, 2014 1:18:11 AM UTC-5, User wrote:
>
> So I tested the migration feature and string to list:string doesn't work.  
> So we are left with the fact that a list:string field with IS_IN_SET 
> multiple=False will not select the current value in an SQLFORM.
>
> Seems kind of like a bug to me, does anyone else think so?
>

I wouldn't call it a bug. It's somewhat of an odd use case.  Using 
IS_IN_SET with multiple=False gives you a non-multiple SELECT widget. Such 
a widget can have only a single option selected, so the web2py SELECT 
helper checks to see if the current value of the field is the same as any 
of the OPTION values. Because the current value of the list:string field is 
a list (and not an individual string), it will not match the value of any 
option values.

Instead, you can just switch to a string field, and if you ever need to 
migrate, just wrap each string in pipe characters (i.e., "|thestring|").

Another option is to create a custom widget:

Field('myfield', 'list:string', requires=IS_IN_SET(...), widget=mywidget)

Finally, you can do:

Field('myfield', 'list:string', requires=IS_IN_SET(..., multiple=(1, 1)),
      comment='Please select only one.')

The above will show a multiple select box instead of a single-select 
drop-down, but it will require the user to select exactly one option (will 
return an error message otherwise).

Anthony

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to