diff options
author | Dave Whiteland <dave@mysociety.org> | 2012-02-17 17:02:47 +0000 |
---|---|---|
committer | Dave Whiteland <dave@mysociety.org> | 2012-02-17 17:02:47 +0000 |
commit | d86885f9ea99566c87bac226eddeb875ba40bba5 (patch) | |
tree | 48e678445f1bd78ca369d9fe4100785a9d3b9288 | |
parent | 2ea254bd33a38d1c93da1fb8c5e730119b21eade (diff) |
use delegation to attach change event to form_category so it survives being repopulated
-rw-r--r-- | web/js/fixmystreet.js | 7 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 5 | ||||
-rw-r--r-- | web/js/southampton.js | 14 |
3 files changed, 13 insertions, 13 deletions
diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js index b1a8f1889..834aa4ed3 100644 --- a/web/js/fixmystreet.js +++ b/web/js/fixmystreet.js @@ -8,7 +8,7 @@ function form_category_onchange() { var args = { category: cat.val() }; - + if ( typeof fixmystreet !== 'undefined' ) { args.latitude = fixmystreet.latitude; args.longitude = fixmystreet.longitude; @@ -159,8 +159,9 @@ $(function(){ timer = window.setTimeout(email_alert_close, 2000); }); - - $('#form_category').change( form_category_onchange ); + // Using delegate here because we *might* be running under a cobrand which isn't jQuery 1.7+ + // Delegation is necessary because #form_category may be replaced during the lifetime of the page + $("#problem_form").delegate("select#form_category", "change", form_category_onchange ); // Geolocation if (geo_position_js.init()) { diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index fa93c2f4c..7cf253bc7 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -355,11 +355,6 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { }, function(data) { $('#councils_text').html(data.councils_text); $('#form_category_row').html(data.category); - /* Need to reset this here as it gets removed when we replace - the HTML for the dropdown */ - if ( data.has_open311 > 0 ) { - $('#form_category').change( form_category_onchange ); - } }); $('#side-form').show(); /* For some reason on IOS5 if you use the jQuery show method it diff --git a/web/js/southampton.js b/web/js/southampton.js index 1f3e16105..290a294ae 100644 --- a/web/js/southampton.js +++ b/web/js/southampton.js @@ -20,8 +20,11 @@ $(function(){ input.val(input.attr('placeholder')); } }).blur(); - - $('#form_category').change(function(){ + + // use on() here because the #form_category may be replaced + // during the page's lifetime + $("#problem_form").on("change.southampton", "select#form_category", + function() { var category = $(this).val(); if ('Potholes' == category) { if (!$('#potholes_extra').length) { @@ -39,12 +42,13 @@ $(function(){ '<option>Deeper than a tennis ball' + '</select></div></div>'; $('#form_title').closest('div.form-field').after(qns); - } + } $('#potholes_extra').show('fast'); } else { $('#potholes_extra').hide('fast'); - } - }).change(); + } + } + ).change(); // change called to trigger (in case we've come in with potholes selected) }); |