Good question.

The issues is the following. When an HTML form is submitted with one 
variable (a)  the query_string contains ?a=value. If it is submitted with 
two values, the query string contains ?a=value&a=other.

When web2py (or any other framework) parses the query_string it may 
find ?a=value or ?a=value&a=other but it does not know if the variable 
comes from a normal input, a select, a multiple select, or checkboxes.

Different frameworks take the same approach. Web2py parses ?a=value into 
request.vars.a='value' and ?a=value&a=other into 
request.vars.a=['value','other']. 

Other frameworks do what you suggest and always use a list: ?a=value into 
request.vars.a=['value'] but the drawback is that they always do it even 
for regular input fields (<input name="a"/>). If we were to do it we would 
have lots more request.vars.a[0] everywhere.

The web2py solution is a compromise, as many other design decisions are.  

Massimo









On Friday, 28 September 2012 17:33:18 UTC-5, MichaelF wrote:
>
> I have a form with a multi-select. If I choose one value and submit, the 
> value is set in request.vars.xxx as a single integer (e.g., 2). If I choose 
> more than one value and submit I get a list of string values (e.g., ['1', 
> '5']). If I select no values I get None.
>
> Expected? Why the inconsistency? Or am I doing something wrong? Why not 
> ['2'], ['1', '5'], and []? That's consistent, orthogonal, etc.
>
> Thanks.
>

-- 



Reply via email to