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 /web/js/southampton.js | |
parent | 2ea254bd33a38d1c93da1fb8c5e730119b21eade (diff) |
use delegation to attach change event to form_category so it survives being repopulated
Diffstat (limited to 'web/js/southampton.js')
-rw-r--r-- | web/js/southampton.js | 14 |
1 files changed, 9 insertions, 5 deletions
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) }); |