Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ <h1 style="color:red;font-family:Inter,Helvetica,sans-serif;font-size:16px;">***
<div style="margin-bottom:1em;">
<!--
Examples (as of March 2022):
SE5 OHU (Southwark): default/"normal" postcode example, fetches 65 LPI addresses
SE5 OHU (Southwark): default/"standard" postcode example, fetches 65 LPI addresses
SE19 1NT (Lambeth): 56 DPA addresses -> 128 LPI addresses (87 "approved"), now requires paginated fetch
HP11 1BR (Bucks): 0 addresses, shows "No addresses found in postcode" error message
HP11 1BC (Bucks): valid postcode according to npm package but not OS, shows OS error message

Example with default value (used for planx "change" & "back" button behavior):
<address-autocomplete postcode="SE5 0HU" id="example-autocomplete" initialAddress="75, COBOURG ROAD, LONDON" />
-->
<address-autocomplete postcode="SE5 0HU" id="example-autocomplete" />
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/components/address-autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class AddressAutocomplete extends LitElement {
@property({ type: String })
label = "Select an address";

@property({ type: String })
initialAddress = "";

@property({ type: String })
osPlacesApiKey = import.meta.env.VITE_APP_OS_PLACES_API_KEY || "";

Expand Down Expand Up @@ -62,6 +65,7 @@ export class AddressAutocomplete extends LitElement {
id: this.id,
required: true,
source: this._options,
defaultValue: this.initialAddress,
showAllValues: true,
tNoResults: () => "No addresses found",
onConfirm: (option: any) => {
Expand Down Expand Up @@ -124,7 +128,8 @@ export class AddressAutocomplete extends LitElement {
);
});

this._options.sort((a, b) => a.localeCompare(b));
const collator = new Intl.Collator([], { numeric: true });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me too 🙂

this._options.sort((a, b) => collator.compare(a, b));
}

// fetch next page of results if they exist
Expand Down