Mike-Heneghan / ALISS

ALISS (A Local Information System for Scotland) is a service to help you find help and support close to you when you need it most.
https://aliss.org
0 stars 0 forks source link

Autocomplete for search input. #45

Closed Mike-Heneghan closed 5 years ago

Mike-Heneghan commented 5 years ago

Autocomplete to be added to allow users to search by town and be suggested a postcode.

This could potentially be achieved using a jQuery library.

Mike-Heneghan commented 5 years ago

Using a free business tool just got a visualisation of a 20km radius around G2 4AA. If we were to create a json representation of towns and they're associated central postcode. Results wouldn't be optimised for distance although it would be useful.

screenshot 2019-03-05 at 12 37 05
Mike-Heneghan commented 5 years ago

15 - 20 locations to handle in a JQuery UI for autocomplete.

Trigger on three letters.

Provide querystring with the inputted. If the third character is not a number, then we know to open the autocomplete for searching by location.

Stick to JQuery as we're already using it.

Locations search approach.

Look at: http://easyautocomplete.com/

Prototype using Dundee, Erskine and Brechin.

Look at Request Data Delay info for returning the search phrase.

Mike-Heneghan commented 5 years ago

To do list:

Mike-Heneghan commented 5 years ago
screenshot 2019-03-08 at 10 13 17 screenshot 2019-03-08 at 10 13 26
Mike-Heneghan commented 5 years ago

The formatting also isn't ideal with the font size and style not consistent with the rest of the aliss project.

Mike-Heneghan commented 5 years ago

To sort out the css is might be best not to import the minified easy-autocomplete easy-autocomplete.min.css as is currently being done. That way the file can be updated to make it's styling more in line with aliss?

Mike-Heneghan commented 5 years ago

The JS required for the easy-autocomplete.

{% block before_body_close %}
  <script type="text/javascript">
    $(document).ready(function(){
      var options = {
        url: function(phrase) {
            return "http://localhost:5000/search/?q=" + phrase;
        },

        data: [
          {"location_name": "Glasgow", "postcode": "G2 4AA"},
          {"location_name": "Edinburgh", "postcode": "EH2 4AD"},
          {"location_name": "Musselburgh", "postcode": "EH21 6UW"},
        ],

        getValue: "location_name",

        minCharNumber: 3,

        list: {

          match: {
            enabled: true
          },

          onSelectItemEvent: function() {
              var value = $("#postcode").getSelectedItemData().postcode;
              $("#postcode").val(value).trigger("change");
            }
          }
        }

      $("#postcode").easyAutocomplete(options);
    });
  </script>
{% endblock %}
Mike-Heneghan commented 5 years ago

The current state of the autocomplete function: https://drive.google.com/file/d/16Wr38nbikT0vVg7RZzIvIn6U7NSBZwvu/view?usp=sharing

Spent some time trying to find the best way to make the styling consistent with the rest of the project although finding it a bit of a time sink. Might be best to leave this until we next meetup so we can review it.

Mike-Heneghan commented 5 years ago

For the autocomplete function have the postcode appear in brackets behind the location i.e Musselburgh (EH21 6UW).

Send in a PR

Mike-Heneghan commented 5 years ago

To do list:

Mike-Heneghan commented 5 years ago
Screenshot 2019-03-18 at 16 03 22
Mike-Heneghan commented 5 years ago

Top cities by population https://en.wikipedia.org/wiki/List_of_towns_and_cities_in_Scotland_by_population

Mike-Heneghan commented 5 years ago

Merged into master