I forget... Don' forget to surround with <script></script> tag...

<script>
{{=XML(your_pass_js_script)}}
</script>


On Sat, Dec 14, 2013 at 3:17 PM, Richard Vézina <ml.richard.vez...@gmail.com
> wrote:

> In the view something like that :
>
> $( document ).ready(function() {
>     $('input#id').bsmselect(...);
> });
>
> It can be pass to the view from the controller, as you want... So you will
> need to do something like that :
>
> {{=XML(your_pass_js_script)}}
>
> :)
>
> Richard
>
>
> On Fri, Dec 13, 2013 at 6:38 PM, Jesse Ferguson <ifl...@gmail.com> wrote:
>
>> sorry to hop in and ask a silly question but, when you say init the js on
>> the field how is that supposed to be done in web2py? Is it done in the
>> view? would it be ideal to put the js in the template and then pass params?
>>
>>  any named optional attribute is passed to the <form> tag
>>>
>>>             for example _class, _id, _style, _action, _method, etc.
>>>
>>>
>> sorry if this doesn't make much sense I'm sure I am just missing the java 
>> knowledge I'm pretty new to programming and am learning through trial and 
>> error...
>>
>>
>>
>> On Friday, December 13, 2013 7:54:48 AM UTC-8, Richard wrote:
>>
>>> You init the js on the field!!
>>>
>>> Richard
>>>
>>>
>>> On Fri, Dec 13, 2013 at 10:20 AM, Kevin Bethke <kevin....@gmail.com>wrote:
>>>
>>>> Well actually I got one more question: How do you change the standard
>>>> form from web2py, to use the bsmselect form?
>>>>
>>>>
>>>> On Fri, Dec 13, 2013 at 4:18 PM, Kevin Bethke <kevin....@gmail.com>wrote:
>>>>
>>>>> Thanks it explains a lot. I will try to work on it as soon as I got
>>>>> the time. Unfortunatly we got a deadline at work which is Christmas. So I
>>>>> will probably not work on it till than.
>>>>>
>>>>>
>>>>> On Fri, Dec 13, 2013 at 3:53 PM, Richard Vézina <ml.richa...@gmail.com
>>>>> > wrote:
>>>>>
>>>>>>  I am sorry about that...
>>>>>>
>>>>>> Web2py default behavior for list:reference or reference is a HTML
>>>>>> Select and option... This is ordered by the navigator base on the 
>>>>>> spelling
>>>>>> of the element... So when you edit your form if you want to maintain the
>>>>>> preexisting order (the one that were there when you select items and 
>>>>>> order
>>>>>> them with bsm) you need to set them in order in the select yourself...
>>>>>> Bsmselect use OL that is Ordered List instead of UL... But it consume a
>>>>>> standard select... So, as long as he get a select with the proper ordered
>>>>>> options he can recreate the prexisting order... That is what the js I 
>>>>>> show
>>>>>> you does...
>>>>>>
>>>>>> ordered_values content the list:reference or the reference value that
>>>>>> are a simple python list... List are items of list are ordered not like
>>>>>> python dict that not preserve order... So I just get the value of the 
>>>>>> field
>>>>>> that is a list object and pass it to the javascript as a list object...
>>>>>> then I create option from that list in javascript like you could do in
>>>>>> web2py with helpers for instance or by generating html yourself...
>>>>>>
>>>>>> Hope it helps.
>>>>>>
>>>>>> Richard
>>>>>>
>>>>>>
>>>>>> On Fri, Dec 13, 2013 at 7:27 AM, Kevin Bethke <kevin....@gmail.com>wrote:
>>>>>>
>>>>>>> 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.richa...@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.richa...@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....@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+un...@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+un...@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+un...@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+un...@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+un...@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.
>>
>
>

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