Skip to content

Javascript locationChanged

James Cobban edited this page Apr 14, 2020 · 14 revisions

function locationChanged(event)

Up: Location Services

The function locationChanged is the change event handler for fields which contain the text representation of a Location. This method is invoked with this a reference to the <input> tag, and is passed an instance of a change Event object as a parameter.

The function performs a number of operations on the value of the <input> element:

  1. Spaces are inserted to separate alphabetic and numeric tokens except for a few exceptional situations. For example "125King St" is corrected to "125 King St", but "3rd Ave" is not changed.
  2. Most words are capitalized. For example "london, middlesex, ontario, canada" is changed to "London, Middlesex, Ontario, Canada".
  3. A set of common words are treated as abbreviations and replaced. This is used to speed up data entry, for example the stand-alone letter "E" is replaced by "England", and "1/2" is replaced by "½". This is also used for words which are not capitalized or are completely capitalized in location names. For example "Lot" is replaced by "lot", and "Mb" is replaced by "MB".
  4. To avoid creating unnecessary alternate versions of rural addresses if the concession portion precedes the lot portion they are swapped. For example "con 4 lot 12" is replaced by "lot 12 con 4".
  5. If the location starts with the word "House" or "Residence" then the beginning of the location, up to and including the first comma, is separated from the remainder and passed as a separate parameter to the server. This avoids creating unhelpful addresses such as "House of Bride's Father, xxxx" while validating the remainder of the address.

Once these normalizations have been completed on the input value, the database is searched using /Family/getLocationJSON.php to find matching instances of Location. If there is only one Location which starts with the string value then the full name of the Location is supplied. If there is more than one Location which starts with the string value then a dialog is displayed to permit selecting one existing Location. If there is no matching Location the application displays a warning that a new Location will be created when the records is updated. For example if you enter "London" this matches the pre-defined Location "London, ON, CA".

Next: function gotLocationJSON(object)

Clone this wiki locally