Thank you very much. By the way, I realized that I sent out without 
completing the subject. :)

On Tuesday, April 5, 2016 at 10:37:02 PM UTC-7, Dave S wrote:
>
>
>
> On Tuesday, April 5, 2016 at 10:04:47 PM UTC-7, SanDiego wrote:
>>
>> I wanted to use translatable fields using T() function. I couldn't find 
>> any information for this in the document. I could only find the info from 
>> forum discussions. But still there are some problems:
>>
>>  
>> COURSES = {'math': T('Math'), 'phy': T('Physics')}
>> ... 
>> Field(course,  requires=IS_IN_SET(COURSES))
>>
>>
>>
> shouldn't you be setting the type to string?   That's the default type, 
> but it may have benefits to be explicit.
>
> works. Only keys (e.g. 'phy') are stored in DB and COURSES dictionary can 
>> be used to display the value (e.g. COURSES['phy']). However, order is 
>> not retained.
>>
>>  
>>
>> Massimo recommends using sets to retain the order here 
>> <https://groups.google.com/d/msg/web2py/Q51pSDExMcE/m-q85-PVggAJ>:
>>
>
> I think he's recommending a tuple of tuples.  (I'm surprised it isn't a 
> list of tuples, as in the book)
> <URL;
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Range--set-and-equality-validators
> >
> then scroll down to IS_IN_SET().
>
>  
>
>>  
>> COURSES = (('math', T('Math')), ('phy', T('Physics')))
>> ... 
>> Field(course,  requires=IS_IN_SET(COURSES))
>>
>>
>> This time order is retained but then display will be problematic.  Probably 
>> we can use list comprehension to display the translated value but not very 
>> intuitive.
>>
>>   
>>
>
> Are you sure the drop down menu isn't created for you?  The example in the 
> book suggests that it is.
>
Dropdown menu is created as expected. When viewing the page after saving 
it, the keys are displayed. I guess I need to write a function to return 
the T() function counterpart value for the view.  

>
>  
>
>> My questions are:
>>
>>    - Is there an easy way for retaining the order and displaying 
>>    correctly?
>>
>>
> This works good for the tuples case as you pointed out. 

> see above 
>
>>
>>    - 
>>    - How can we set the default value? e.g. if we set default to 'phy', 
>>    I still want to show COURSES['phy'] in the dropdown menu in the form
>>
>>
> would that be Field("Courses", "string",  default=COURSES[1], 
> requires=IS_IN_SET(COURSES)) ?
>
>>
>>    - Would it be possible to add more info and examples for this 
>>    function in the documentation? I think this is very basic function and 
>> used 
>>    extensively.
>>
>> The material at the URL seems clear enough, although it doesn't show 
> using the T() function.  What do you suggest is missing?
>

I couldn't find the help page. I searched the book both on the page (See 
attachments) and using Google but that is not listed. Is there anyway to 
improve the search feature? The material is sufficient. I should have gone 
through the forms/validators section more thoroughly. 

>
> /dps
>
Thanks.
S/ 

-- 
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/d/optout.

Reply via email to