thanks but to be honest now I'm even more confused.
why do you need a piece of jquery code in a javascript variable. I sopose
you included the entire jquery library.
Why do you do the ordering with javascript and not with python is there a
special reason for this? I think I just explained the last question  by
looking at the code again. The document ready function is executed every
time you add or remove an element from the list?
the javascript variable ordered_values="%s" is filled from the represent
python variable?
And my last question do you implement the multiple select into a form?
Sry for all those questions but I'm still learning and the need for this to
work really pushes my skills and knowledge beyond its limits.


On Thu, Dec 12, 2013 at 3:49 PM, Richard Vézina <ml.richard.vez...@gmail.com
> wrote:

> It's a bit hacky but it works...
>
> :)
>
> Richard
>
>
> On Thu, Dec 12, 2013 at 9:48 AM, Richard Vézina <
> ml.richard.vez...@gmail.com> wrote:
>
>> Don't bother with the php thing...
>>
>> Just look the data structure of the select...
>>
>> Here what I do to restore proper order on update form :
>>
>> controller_view_js += """
>> var ordered_values = ''%s'';
>> $(document).ready(function() {
>>     if(ordered_values != "None") {
>>         $.each(ordered_values, function(i, val) {
>>             $("select[name=field_name]").append("<option
>> value=\'"+ordered_values[i]+"\'>"+
>>                 $("select[name=field_name]
>> option[value="+ordered_values[i]+"]").text()+"</option>");
>>         });
>>         $("select[name=field_name] option:selected").remove();
>>         $.each(ordered_values, function(i, val) {
>>             $("select[name=field_name]
>> option[value="+ordered_values[i]+"]").attr("selected", "selected");
>>         });
>>     };
>> });""" % [int(ID) for ID in ordered_values_query]
>>
>> controller_view_js is a variable containing a piece of jquery that I pass
>> to the view from the controller... What it does put the options into the
>> proper order or how they were ordered at the input... All this is because
>> web2py don't use "ol" list out of the box... So I manage thing to not
>> require ol.
>>
>> The ordered_values_query contain the value of the field field_name for
>> the given record...
>>
>> I had to set a representation like this too :
>>
>> represent=lambda values, row: ', '.join(map(lambda id:
>> db.ref_referenced_table(id).represent_field, values)) if values != [] or
>> None else T('N/A')
>>
>> Hope it helps.
>>
>> Richard
>>
>>
>> On Thu, Dec 12, 2013 at 4:07 AM, BlueShadow <kevin.bet...@gmail.com>wrote:
>>
>>> thanks for your offer I'm working my way through the example code but my
>>> biggest problem is that php site. I don't know php. But from what I get
>>> from the php code is that all the sample cities need to be in an unordered
>>> list environment <ul><li></li>...</ul>
>>> but this form part of the bsmselect example really confuses me.
>>>
>>> <h1>Example 1: Typical Usage</h1>
>>>
>>> <form action="./example_results.php" method="post">
>>>
>>>
>>>     <label for="cities1">What are your favorite cities?</label>
>>>
>>>     <select id="cities1" multiple="multiple" name="cities[]" title="Click 
>>> to Select a City" class="sminit">
>>>
>>>       <option>Amsterdam</option>
>>>
>>>     </select>
>>>     <p><input type="submit" name="submit" value="submit" /></p>
>>>
>>>   </form>
>>>
>>>
>>> especially the php file in form action=""
>>> <?php
>>>
>>> if(!empty($_POST['submit'])) {
>>>
>>>   echo "<html>\n<body style='width: 400px; margin: 2em auto;
>>> font-family: Arial;'>";
>>>
>>>   if(!empty($_POST['cities'])) {
>>>
>>>     echo "\n<p><strong>You selected the following
>>> cities:</strong></p>\n<ul>";
>>>
>>>     foreach($_POST['cities'] as $city) {
>>>
>>>       // exclude any items with chars we don't want, just in case
>>> someone is playing
>>>       if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $city)) continue;
>>>
>>>       // print the city
>>>       echo "\n\t<li>" . htmlspecialchars($city) . "</li>";
>>>     }
>>>
>>>     echo "\n</ul>";
>>>
>>>   } else {
>>>     echo "\n<p>No items selected</p>";
>>>   }
>>>
>>>   echo "\n<p><a href='index.html'>Try Again?</a></p>";
>>>
>>>   echo "\n</body>\n</html>";
>>>
>>> } else {
>>>   // if someone arrived here not having started at example.html
>>>   // then show example.html instead
>>>   require("index.html");
>>>
>>> }
>>>
>>>
>>> It seems to me that there is an entire html document in this php file.
>>>
>>>  --
>>> 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.
>>>
>>
>>
>  --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/3HTTdoGnCAA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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