aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index dd9167185..35a655c86 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -675,13 +675,21 @@ $.extend(fixmystreet.set_up, {
// The inspect form submit button can change depending on the selected state
$("#report_inspect_form [name=state]").change(function(){
var state = $(this).val();
- var $submit = $("#report_inspect_form input[type=submit]");
+ var $inspect_form = $("#report_inspect_form");
+ var $submit = $inspect_form.find("input[type=submit]");
var value = $submit.attr('data-value-'+state);
if (value !== undefined) {
$submit.val(value);
} else {
$submit.val($submit.data('valueOriginal'));
}
+
+ // We might also have a response template to preselect for the new state
+ var $select = $inspect_form.find("select.js-template-name");
+ var $option = $select.find("option[data-problem-state='"+state+"']").first();
+ if ($option.length) {
+ $select.val($option.val()).change();
+ }
}).change();
$('.js-toggle-public-update').each(function() {
@@ -1001,9 +1009,20 @@ $.extend(fixmystreet.set_up, {
},
response_templates: function() {
+ // If the user has manually edited the contents of an update field,
+ // mark it as dirty so it doesn't get clobbered if we select another
+ // response template. If the field is empty, it's not considered dirty.
+ $('.js-template-name').each(function() {
+ var $input = $('#' + $(this).data('for'));
+ $input.change(function() { $(this).data('dirty', !/^\s*$/.test($(this).val())); });
+ });
+
$('.js-template-name').change(function() {
var $this = $(this);
- $('#' + $this.data('for')).val($this.val());
+ var $input = $('#' + $this.data('for'));
+ if (!$input.data('dirty')) {
+ $input.val($this.val());
+ }
});
}
});