Ok, I had a closer look at what's going on... Test :
No plugin (no chosen), no validator (no is_in_db), field type list:reference so multiselect. What's happen : Select options will be sorted alphanumerically so if first_name is the id represent set with format='%(first_name)s' options will be ordered alphabetically. Then the selecting options will be stored in the order they appears in the select options html list. Trying to define the order with default=['35', '18', '38'] that goes against the alphabetic order of the select options get overrided and the order of stored field entry is the same as the order of the select option list. Conclusion : I wrongly thought that chosen was returning the selected element in the order they have been selected by the user... I was miss leading because at first I thought that the default behavior or web2py was to order the selected input option base on id of the referenced table. So I was only looking for a different behavior. The first tests I made was to printing the content of form.vars.referencefiedl, so I thought that because the id was not in order (not [1,2,3]) but [2,3,1] for example, it means that web2py was doing something behind me... I was wrong. Using the asmselect (http://code.google.com/p/jquery-asmselect/, see also this fork : https://github.com/vicb/bsmSelect) I have been able to do what I want only at creation of a record... On update it not working so far... So, it's not a web2py issue... Only remaining issue is that records can't be update without the lost of the initial user selected elements order. So a complementary field (a uses "hidded" field to store the order of the element) will be needed to keep track of the order to make it usables. Thanks. Richard On Thu, May 3, 2012 at 10:21 AM, Richard Vézina <[email protected] > wrote: > Wait I think it return the element base on the orderby... > > I test further. > > Richard > > > On Thu, May 3, 2012 at 10:05 AM, Richard Vézina < > [email protected]> wrote: > >> Think that "sort=False" does the trick!! >> >> Thanks for help, I think you can close the issue... Do you want I leave >> the solution with the issue? >> >> Richard >> >> >> On Thu, May 3, 2012 at 10:02 AM, Richard Vézina < >> [email protected]> wrote: >> >>> Ok, I remove the IS_IN_DB validator and now I get unordered list... So, >>> look like it the problem... >>> >>> I will try to change it... >>> >>> Richard >>> >>> >>> On Thu, May 3, 2012 at 9:53 AM, Richard Vézina < >>> [email protected]> wrote: >>> >>>> I use IS_IN_DB with a set not the table directly... >>>> >>>> analyst_set = db((db.auth_group.role=='analyst') & >>>> (db.auth_user.id==db.auth_membership.user_id) >>>> & (db.auth_membership.group_id==db.auth_group.id)) >>>> >>>> requires=IS_IN_DB(analyst_set,'auth_user.id','%(initials)s',\ >>>> multiple=True,cache=(cache.ram, 3600)), >>>> >>>> So, maybe it is the IS_IN_DB validator that order the list at the end >>>> of the process before returning the list to the DAL. >>>> >>>> Richard >>>> >>>> On Wed, May 2, 2012 at 11:12 PM, Massimo Di Pierro < >>>> [email protected]> wrote: >>>> >>>>> Are you talking about the IS_IN_SET() validator? I need to see some >>>>> code. There is nothing in DAL that cases this. It must be a validator. So >>>>> it depends on what you are using. >>>>> >>>>> >>>>> On Wednesday, 2 May 2012 17:29:35 UTC-5, Richard wrote: >>>>>> >>>>>> Ok DAL do will return [1,2,3] in case of the user has select the >>>>>> first 3 element of the referenced table. >>>>>> >>>>>> What Choosen plugin return (and what I would to be stored in database >>>>>> field) could be [1,3,2] or [3,1,2] or what ever other order in which the >>>>>> user had pick those referenced elements. Choosen allow that when use >>>>>> multiple option. >>>>>> >>>>>> So I would like that the DAL return at the database level the order >>>>>> in which the element have been entered in the field in case of use of >>>>>> plugin like choosen. Off course it is not applying if someone is not >>>>>> using >>>>>> a plugin because you can't know in which order the element have been >>>>>> selected. >>>>>> >>>>>> Now, I think that what prevent the DAL to return a unordered list to >>>>>> the database is the use of dict... >>>>>> >>>>>> I think I found a work around... But I didn't have time to implement >>>>>> it... It consist of creating an other field to store the content of the >>>>>> form.vars.field (list:reference field). So having 2 fields instead of >>>>>> 1... >>>>>> >>>>>> Hope it more clear. >>>>>> >>>>>> Richard >>>>>> >>>>>> On Wed, May 2, 2012 at 4:52 PM, Massimo Di Pierro < >>>>>> [email protected]> wrote: >>>>>> >>>>>>> Richard, I am at a loss about this. the dal does not sort, nor does >>>>>>> the validator. Can you show me and example to reproduce this sorting? >>>>>>> >>>>>>> >>>>>>> On Thursday, 19 April 2012 16:14:50 UTC-5, Richard wrote: >>>>>>>> >>>>>>>> Issue 768 <http://code.google.com/p/web2py/issues/detail?id=768>: >>>>>>>> Allow >>>>>>>> insert of unsorted or unordered list:reference type field values >>>>>>>> On Thu, Apr 19, 2012 at 5:08 PM, Richard Vézina < >>>>>>>> [email protected]> wrote: >>>>>>>> >>>>>>>>> Found this http://stackoverflow.com/****questions/1867861/python-* >>>>>>>>> *dicti**onary-keep-keys-values-**in-**same-order-as-declared<http://stackoverflow.com/questions/1867861/python-dictionary-keep-keys-values-in-same-order-as-declared> >>>>>>>>> on >>>>>>>>> stackoverflow where the most rated post redirect here : >>>>>>>>> http://dev.pocoo.org/hg/**sandbo**x/raw-file/tip/odict.py<http://dev.pocoo.org/hg/sandbox/raw-file/tip/odict.py> >>>>>>>>> >>>>>>>>> Notice, it will download odict.py into your computer that contain >>>>>>>>> a class supposing to allow preservation of initial order in a python >>>>>>>>> dict... >>>>>>>>> >>>>>>>>> I think, it could be nice to have this class added to web2py in >>>>>>>>> order to allow insert into database of unordered list:reference field >>>>>>>>> input... >>>>>>>>> >>>>>>>>> Since this could be slow (not in case of few value I think), it >>>>>>>>> could be a choice offer to the user like : list:reference sorted or >>>>>>>>> list:reference unsorted... >>>>>>>>> >>>>>>>>> What do you think?? >>>>>>>>> >>>>>>>>> Richard >>>>>>>>> >>>>>>>>> >>>>>>>>> On Thu, Apr 19, 2012 at 4:59 PM, Richard Vézina < >>>>>>>>> [email protected]> wrote: >>>>>>>>> >>>>>>>>>> Some progress... >>>>>>>>>> >>>>>>>>>> I just make a check and chosen plugin multiple select option >>>>>>>>>> return a unordered list of the picked element by the user... >>>>>>>>>> >>>>>>>>>> So, now, I think that it could be nice if web2py allow some way >>>>>>>>>> to determine in case of use of chosen kind of plugin to store a >>>>>>>>>> unordered >>>>>>>>>> list in list:reference field... >>>>>>>>>> >>>>>>>>>> I think that it is near line 207 (web2py 1.99.4) gluon/sqlhtml >>>>>>>>>> that we have to make change : >>>>>>>>>> >>>>>>>>>> class OptionsWidget(FormWidget): >>>>>>>>>> >>>>>>>>>> @staticmethod >>>>>>>>>> def has_options(field): >>>>>>>>>> """ >>>>>>>>>> checks if the field has selectable options >>>>>>>>>> >>>>>>>>>> :param field: the field needing checking >>>>>>>>>> :returns: True if the field has options >>>>>>>>>> """ >>>>>>>>>> >>>>>>>>>> return hasattr(field.requires, 'options') >>>>>>>>>> >>>>>>>>>> @classmethod >>>>>>>>>> def widget(cls, field, value, **attributes): >>>>>>>>>> """ >>>>>>>>>> generates a SELECT tag, including OPTIONs (only 1 option >>>>>>>>>> allowed) >>>>>>>>>> >>>>>>>>>> see also: :meth:`FormWidget.widget` >>>>>>>>>> """ >>>>>>>>>> default = dict(value=value) # HERE!!!!!!!! >>>>>>>>>> >>>>>>>>>> I am not pretty sure actually... And I don't really know, what >>>>>>>>>> could be done to keep submit multiple list order in case of plugin >>>>>>>>>> use... >>>>>>>>>> >>>>>>>>>> I try naively to replace >>>>>>>>>> >>>>>>>>>> default = dict(value=value) >>>>>>>>>> >>>>>>>>>> By >>>>>>>>>> >>>>>>>>>> defautl = value >>>>>>>>>> >>>>>>>>>> But it failed. >>>>>>>>>> >>>>>>>>>> Richard >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Thu, Apr 19, 2012 at 3:43 PM, Richard Vézina < >>>>>>>>>> [email protected]> wrote: >>>>>>>>>> >>>>>>>>>>> This is a part of the solution I think : >>>>>>>>>>> >>>>>>>>>>> http://www.ryancramer.com/**jour**nal/entries/select_**multiple/<http://www.ryancramer.com/journal/entries/select_multiple/> >>>>>>>>>>> >>>>>>>>>>> Richard >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> On Thu, Apr 19, 2012 at 3:08 PM, Richard < >>>>>>>>>>> [email protected]> wrote: >>>>>>>>>>> >>>>>>>>>>>> Hello, >>>>>>>>>>>> >>>>>>>>>>>> I would know if there is a way to tell to list:reference to not >>>>>>>>>>>> order the id of the reference table to keep the order in wich the >>>>>>>>>>>> user has >>>>>>>>>>>> pick those element... At the same time I just thought that this >>>>>>>>>>>> concept is >>>>>>>>>>>> useless except in case you use some javascript plugin like Chosen >>>>>>>>>>>> Multiple >>>>>>>>>>>> Select >>>>>>>>>>>> (http://harvesthq.github.com/**c**hosen/<http://harvesthq.github.com/chosen/>) >>>>>>>>>>>> because, you pick the element in a list and there is no way to >>>>>>>>>>>> know which >>>>>>>>>>>> element in the list the user has selected first. >>>>>>>>>>>> >>>>>>>>>>>> My need is to allow users to select element from an other table >>>>>>>>>>>> and keep a more informative those selected thing. Like the >>>>>>>>>>>> ingredient on >>>>>>>>>>>> the back panel of food box, the first ingredient more abondant >>>>>>>>>>>> than the >>>>>>>>>>>> second an so on. >>>>>>>>>>>> >>>>>>>>>>>> So, for now I think I am stock with a text field. I would avoid >>>>>>>>>>>> a free text field because I would prefer user to always use the >>>>>>>>>>>> same name >>>>>>>>>>>> for the same thing, but I can't do it with text type field. What I >>>>>>>>>>>> thought >>>>>>>>>>>> is a list:reference field and a button beside the field to allow >>>>>>>>>>>> allow user >>>>>>>>>>>> to add missing element name in the foreign table if need without >>>>>>>>>>>> leave the >>>>>>>>>>>> original form. This can be done easily with the select or add >>>>>>>>>>>> web2py slice >>>>>>>>>>>> : http://www.web2pyslices.com/**** >>>>>>>>>>>> slice/show/1446/widget-select-****or-add-option<http://www.web2pyslices.com/slice/show/1446/widget-select-or-add-option>. >>>>>>>>>>>> Thanks to the author. >>>>>>>>>>>> >>>>>>>>>>>> But, I think that keeping the order of the selected element >>>>>>>>>>>> can't be done?? >>>>>>>>>>>> >>>>>>>>>>>> Thanks for help. >>>>>>>>>>>> >>>>>>>>>>>> Richard >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>> >>>> >>> >> >

