diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/cobrands/fixmystreet-uk-councils/council_validation_rules.js | 38 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 31 | ||||
-rw-r--r-- | web/js/validation_rules.js | 6 |
3 files changed, 73 insertions, 2 deletions
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; |