aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2018-10-26 09:14:22 +0100
committerDave Arter <davea@mysociety.org>2018-11-02 15:54:09 +0000
commite5eab60d971bbf97583a555d72374085ec45b5d4 (patch)
tree0384b5c6567b1afd7a9e61360a80ba471960763a
parentb27cd116c94f2f1edb97d32a9c7f0f9c7cf10aaf (diff)
Sort category groups correctly
Previously if there was a mix of groups and top-level categories they weren’t sorted together.
-rw-r--r--.cypress/cypress/integration/category_tests.js4
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js11
2 files changed, 13 insertions, 2 deletions
diff --git a/.cypress/cypress/integration/category_tests.js b/.cypress/cypress/integration/category_tests.js
index 5135ef842..a40ec3fcd 100644
--- a/.cypress/cypress/integration/category_tests.js
+++ b/.cypress/cypress/integration/category_tests.js
@@ -13,7 +13,7 @@ describe('Basic categories', function() {
cy.get('#map_box').click(210, 200);
cy.wait('@report-ajax');
cy.get('[name=category]').should('not.be.visible');
- var categories = ['-- Pick a category --', 'Graffiti', 'Potholes', 'Street lighting', 'Other', 'Bins' ];
+ var categories = ['-- Pick a category --', 'Bins', 'Graffiti', 'Potholes', 'Street lighting', 'Other' ];
cy.get('select:eq(3) option').each(function (obj, i) {
expect(obj[0].value).to.equal(categories[i]);
});
@@ -29,7 +29,7 @@ describe('Basic categories', function() {
cy.route('/report/new/ajax*').as('report-ajax');
cy.visit('/report/new?latitude=51.496194&longitude=-2.603482');
cy.get('[name=category]').should('not.be.visible');
- var categories = ['-- Pick a category --', 'Graffiti', 'Potholes', 'Street lighting', 'Other', 'Bins' ];
+ var categories = ['-- Pick a category --', 'Bins', 'Graffiti', 'Potholes', 'Street lighting', 'Other' ];
cy.get('select:eq(1) option').each(function (obj, i) {
expect(obj[0].value).to.equal(categories[i]);
});
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index af69a536e..97d53dd01 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -504,6 +504,17 @@ $.extend(fixmystreet.set_up, {
add_option(this);
}
});
+ // Sort elements in place, but leave the first 'pick a category' option alone
+ $group_select.find("option").slice(1).sort(function(a, b) {
+ // 'Other' should always be at the end.
+ if (a.label === 'Other') {
+ return 1;
+ }
+ if (b.label === 'Other') {
+ return -1;
+ }
+ return a.label > b.label ? 1 : -1;
+ }).appendTo($group_select);
$group_select.change();
},