This javascript worked in older version of web2py - not in trunk version.

102 views
Skip to first unread message

Johann Spies

unread,
Jul 24, 2013, 3:54:28 AM7/24/13
to web...@googlegroups.com
The html produced in by the view:

<div class="row-fluid" style="background-color: #E6E6FA;">
<div class="span3">
<p>2. What is the nature of your affiliation with the African university?</p>
</div>
<div class="span9">
<p></p>
<table id="survey_a2" class="generic-widget" name="a2">
<tbody>
<tr>
<td>
<input id="a21" type="radio" value="1" name="a2">
<label for="a21">Permanent and full-time university staff member</label>
</td>
</tr>
<tr>
<td>
<input id="a22" type="radio" value="2" name="a2">
<label for="a22">Permanent and part-time university staff member</label>
</td>
</tr>
<tr>
<td>
<input id="a23" type="radio" value="3" name="a2">
<label for="a23">University staff member appointed on a fixed-term contract</label>
</td>
</tr>
<tr>
<td>
<input id="a24" type="radio" value="4" name="a2">
<label for="a24">Post-doctoral fellow</label>
</td>
</tr>
<tr>
<td>
<input id="a25" type="radio" value="5" name="a2">
<label for="a25">Research fellow / teaching fellow / visiting scholar / extraordinary professor </label>
</td>
</tr>
<tr>
<td>
<input id="a26" type="radio" value="6" name="a2">
<label for="a26">Officially retired but still assisting the university</label>
</td>
</tr>
<tr>
<td>
<input id="a27" type="radio" value="7" name="a2">
<label for="a27">Other</label>
</td>
</tr>
</tbody>
</table>
<p></p>
</div>
</div>
<div class="row-fluid" style="background-color: #E6E6FA;">
<div class="span12">
<div id="a2_other" style="display: none;">
<div class="span3">
<p>   Please specify 'other'</p>
</div>
<div class="span9">
<p>
<input id="survey_a2_other" class="string" type="text" value="" style="width:60%;" name="a2_other">
</p>
</div>
</div>
</div>
</div>

The javascript part:

jQuery(document).ready(function(){
   jQuery('#a2_other').hide();
 
   jQuery('#survey_a2').change(function(){
        if(jQuery('#a27').attr('checked')){
            jQuery('#a2_other').show();}
        else {jQuery('#a2_other').hide();}});
   
       
});
</script>

#a2_other is hidden but when #a27 is clicked, it is not recognised by jQuery and the field stays hidden.

This  (and other similar constructs in the form) was working perfectly in an older version of the app - not so with the trunk version.

I have not been able to determine the exact course of the problem.

In the newer version I replicated the Welcome app and copied the models, controller and default/index.html from the older app.

Regards
Johann

Johann Spies

unread,
Jul 24, 2013, 4:46:34 AM7/24/13
to web...@googlegroups.com


On Wednesday, 24 July 2013 09:54:28 UTC+2, Johann Spies wrote:

I have not been able to determine the exact course of the problem.


It seems that static/js/jquery.js is the problem.  Replacing the file in the working app with the one from the Welcome app, breaks things.

Regards
Johann

Richard Vézina

unread,
Jul 24, 2013, 12:42:25 PM7/24/13
to web2py-users
Johann don't forget to update the other files too...


Richard

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

Johann Spies

unread,
Jul 25, 2013, 6:12:43 AM7/25/13
to web...@googlegroups.com
I did that (again) now and immediately the javascript stopped working as expected. 

Then I just put back the file jsquery (/*! jQuery v...@1.8.0) from the older copy of the app and the javascript worked again as expected.

Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

Richard Vézina

unread,
Jul 25, 2013, 9:36:01 AM7/25/13
to web2py-users
So, some of your jquery code use deprecated stuff... .live() deprecated for instance, replaced by .on() 

Maybe look at the jquery change log and see what the removed and than make a grep 'deprecated jquery' on your code base!!

Richard

Paolo Caruccio

unread,
Jul 25, 2013, 2:06:50 PM7/25/13
to
Yes the issue is due to jquery version. In your code, please replace .attr() with .prop() (for reference see http://api.jquery.com/prop/)

Below code worked in my test:

<script>

jQuery
(document).ready(function(){


   jQuery
('#a2_other').hide();
 
   jQuery
('#survey_a2').change(function(){

          console
.log('table changed', jQuery('#a27').attr('checked'));
       
if(jQuery('#a27').prop('checked')){

            jQuery
('#a2_other').show();}
       
else {jQuery('#a2_other').hide();}
   
});
   
       
});
</script>

Johann Spies

unread,
Jul 26, 2013, 2:56:50 AM7/26/13
to web...@googlegroups.com
Thanks Richard and Paolo.

Regards
Johann
Reply all
Reply to author
Forward
0 new messages