aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--templates/web/base/js/translation_strings.html5
-rw-r--r--templates/web/bathnes/footer_extra_js.html3
-rw-r--r--templates/web/bromley/footer_extra_js.html1
-rw-r--r--templates/web/buckinghamshire/footer_extra_js.html3
-rw-r--r--templates/web/fixmystreet.com/footer_extra_js.html1
-rw-r--r--templates/web/lincolnshire/footer_extra_js.html3
-rw-r--r--templates/web/rutland/footer_extra_js.html3
-rw-r--r--web/cobrands/fixmystreet-uk-councils/council_validation_rules.js38
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js31
-rw-r--r--web/js/validation_rules.js6
10 files changed, 91 insertions, 3 deletions
diff --git a/templates/web/base/js/translation_strings.html b/templates/web/base/js/translation_strings.html
index bd8144a63..1b0735919 100644
--- a/templates/web/base/js/translation_strings.html
+++ b/templates/web/base/js/translation_strings.html
@@ -5,7 +5,10 @@ fixmystreet.password_minimum_length = [% c.cobrand.password_minimum_length %];
translation_strings = {
update: '[% loc('Please enter a message') | replace("'", "\\'") %]',
title: '[% loc('Please enter a subject') | replace("'", "\\'") %]',
- detail: '[% loc('Please enter some details') | replace("'", "\\'") %]',
+ detail: {
+ required: '[% loc('Please enter some details') | replace("'", "\\'") %]',
+ maxlength: '[% loc('Reports are limited to {0} characters in length. Please shorten your report') | replace("'", "\\'") %]',
+ },
name: {
required: '[% loc('Please enter your name') | replace("'", "\\'") %]',
validName: '[% loc('Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below') | replace("'", "\\'") %]'
diff --git a/templates/web/bathnes/footer_extra_js.html b/templates/web/bathnes/footer_extra_js.html
new file mode 100644
index 000000000..8113befc9
--- /dev/null
+++ b/templates/web/bathnes/footer_extra_js.html
@@ -0,0 +1,3 @@
+[% scripts.push(
+ version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'),
+) %]
diff --git a/templates/web/bromley/footer_extra_js.html b/templates/web/bromley/footer_extra_js.html
index 0b69cf5ad..3c8711c39 100644
--- a/templates/web/bromley/footer_extra_js.html
+++ b/templates/web/bromley/footer_extra_js.html
@@ -1,4 +1,5 @@
[% scripts.push(
version('/jslib/jquery-1.7.2.min.js'),
version('/cobrands/bromley/a-z-nav.js'),
+ version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'),
) %]
diff --git a/templates/web/buckinghamshire/footer_extra_js.html b/templates/web/buckinghamshire/footer_extra_js.html
new file mode 100644
index 000000000..8113befc9
--- /dev/null
+++ b/templates/web/buckinghamshire/footer_extra_js.html
@@ -0,0 +1,3 @@
+[% scripts.push(
+ version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'),
+) %]
diff --git a/templates/web/fixmystreet.com/footer_extra_js.html b/templates/web/fixmystreet.com/footer_extra_js.html
index c0c4ff80e..9282490f8 100644
--- a/templates/web/fixmystreet.com/footer_extra_js.html
+++ b/templates/web/fixmystreet.com/footer_extra_js.html
@@ -11,6 +11,7 @@ IF bodyclass.match('mappage');
scripts.push( version('/cobrands/lincolnshire/assets.js') );
scripts.push( version('/cobrands/oxfordshire/assets.js') );
scripts.push( version('/cobrands/highways/assets.js') );
+ scripts.push( version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js') );
scripts.push(
version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'),
);
diff --git a/templates/web/lincolnshire/footer_extra_js.html b/templates/web/lincolnshire/footer_extra_js.html
new file mode 100644
index 000000000..8113befc9
--- /dev/null
+++ b/templates/web/lincolnshire/footer_extra_js.html
@@ -0,0 +1,3 @@
+[% scripts.push(
+ version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'),
+) %]
diff --git a/templates/web/rutland/footer_extra_js.html b/templates/web/rutland/footer_extra_js.html
new file mode 100644
index 000000000..8113befc9
--- /dev/null
+++ b/templates/web/rutland/footer_extra_js.html
@@ -0,0 +1,3 @@
+[% scripts.push(
+ version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'),
+) %]
diff --git a/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js
new file mode 100644
index 000000000..1421687f8
--- /dev/null
+++ b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js
@@ -0,0 +1,38 @@
+confirm_validation_rules = {
+ name: {
+ required: true,
+ maxlength: 50
+ },
+ phone: {
+ maxlength: 20
+ },
+ detail: {
+ required: true,
+ maxlength: 2000
+ }
+};
+
+body_validation_rules['Buckinghamshire County Council'] = confirm_validation_rules;
+body_validation_rules['Lincolnshire County Council'] = confirm_validation_rules;
+body_validation_rules['Bath and North East Somerset Council'] = confirm_validation_rules;
+
+body_validation_rules['Rutland County Council'] = {
+ name: {
+ required: true,
+ maxlength: 40
+ }
+};
+
+body_validation_rules['Bromley Council'] = {
+ detail: {
+ required: true,
+ maxlength: 1750
+ }
+};
+
+body_validation_rules['Oxfordshire County Council'] = {
+ detail: {
+ required: true,
+ maxlength: 1700
+ }
+};
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index 5a326e6f9..9d3b9388f 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -282,7 +282,7 @@ $.extend(fixmystreet.set_up, {
var submitted = false;
$("form.validate").each(function(){
- $(this).validate({
+ fixmystreet.validator = $(this).validate({
rules: validation_rules,
messages: translation_strings,
onkeyup: false,
@@ -431,10 +431,39 @@ $.extend(fixmystreet.set_up, {
$category_meta.empty();
}
+ // remove existing validation rules
+ validation_rules = fixmystreet.validator.settings.rules;
+ $.each(validation_rules, function(rule) {
+ var $el = $('#form_' + rule);
+ if ($el.length) {
+ $el.rules('remove');
+ }
+ });
+ // apply new validation rules
+ fixmystreet.set_up.reapply_validation(core_validation_rules);
+ $.each(data.bodies, function(index, body) {
+ if ( body_validation_rules[body] ) {
+ var rules = body_validation_rules[body];
+ fixmystreet.set_up.reapply_validation(rules);
+ }
+ });
+
$(fixmystreet).trigger('report_new:category_change', [ $(this) ]);
});
},
+ reapply_validation: function(rules) {
+ if (rules === undefined) {
+ return;
+ }
+ $.each(rules, function(name, rule) {
+ var $el = $('#form_' + name);
+ if ($el.length) {
+ $el.rules('add', rule);
+ }
+ });
+ },
+
category_groups: function() {
var $category_select = $("select#form_category.js-grouped-select");
if ($category_select.length === 0) {
diff --git a/web/js/validation_rules.js b/web/js/validation_rules.js
index e6d745336..b8f09ef1e 100644
--- a/web/js/validation_rules.js
+++ b/web/js/validation_rules.js
@@ -1,4 +1,4 @@
- validation_rules = {
+ core_validation_rules = {
title: { required: true },
detail: { required: true },
update: { required: true },
@@ -9,3 +9,7 @@
}
}
};
+
+ body_validation_rules = {};
+
+ validation_rules = core_validation_rules;