View: PlaceSearch

The PlaceSearch view can integrated into your application so your users have the ability to select which location they would like to see weather data for.

Note: The PlaceSearch view is only available using the JavaScript library method.

JavaScript: Aeris.wxblox.views.PlaceSearch

Server Path: n/a

Data API/AMP Usage: 1 API hit per query

Supported Plans API Developer,  API Basic,  API Premium

Configuration

The following configuration options are supported by this view:

Option Default Description
searchOnChange true (boolean) When set to false, user will need to hit enter or the search icon after typing to retrieve list of applicable places. Default value will display results as the user types.
enabled true (boolean) Whether or not this view is enabled. If false then the view will not be rendered and it's required data will not be requested. This option is typically only applicable for views contained within a parent layout.
metric false (boolean) Whether or not to display units in metric. The method setUnits() can be used at runtime once a view has rendered to change the units currently displayed.
renderNoData true (boolean) Whether or not the view should be rendered if data was not returned or not available
request undefined (object) An object containing the default Aeris Weather API request options to use for the views's data request where applicable. These parameters can also be overriden in the load(:params) method when rendering the view using the JavaScript method.

Methods

The following methods are supported by instances of this view (JavaScript method only):

clear()

​Clears the current search results listing from the most recent query

reset()

Resets the view by clearing the text field and removing all search results from the most recent query

enabled() [boolean] Whether or not the component is currently enabled. When false, the component will not be rendered and data required for the component will not be requested.
hide() Hides the component's DOM element.
isMetric() [boolean] Whether or not the component is currently displaying Metric units.
load(:object) Requests data required by the component and renders the result. For components that don't require remote data requests, this method will call render() immediately. An optional object of request parameters can be provided to use for the request.
params() [object] Returns the latest request parameters used when loading data.
refresh() Re-renders the component using the cached data that was previously loaded.
rendered() [boolean] Whether or not the component has rendered.
setMetric(:boolean) Convenience method for setUnits() to toggle Metric units, where true sets the component's units to Metric and false uses Imperial.
setUnits(:number) Updates the unit type being displayed by the component, where 0 is Imperial and 1 is Metric.
show() Shows the component's DOM element.
units() [number] The current unit type being displayed, where 0 is Imperial and 1 is Metric.

Events

The following events are triggered by instances of this view (JavaScript method only):

select ​Triggered when an item in the resulting listing has been selected by the user, either by clicking/tapping on a result or hitting Enter while a result is highlighted
key:enter ​Triggered when the Enter key has been detected while a result is highlighted in the list
key:escape ​Triggered when the Escape key has been detected while the search field is within focus
change:units Triggered when the component's unit type has changed (e.g. metric or imperial).
load:done Triggered after the component's data has loaded but before rendering the component.
load:error Triggered when an error occurs while requesting the component's data.
load:start Triggered immediately before the component's data request begins loading.
render Alias for render:after.
render:after Triggered after the component has rendered and any additional DOM elements and/or events have been setup as needed for the component.
render:before Triggered immediately before the component is rendered, allowing you to access and modify the data used in the template before getting rendered.

Examples

Use the following examples to assist with getting started using this view. Select your WeatherBlox integration method for example code specific to that usage.

JavaScript
API via Package
API via URL

The first example below can be pasted into the body of your HTML document. For each additional snippet, you can replace the snippet within the first example which is located between the JavaScript comments.

Displays the primary place search field:

<link href="https://cdn.aerisapi.com/wxblox/aeris-wxblox.css" rel="stylesheet"/>
<script src="https://cdn.aerisapi.com/wxblox/aeris-wxblox.min.js"></script>

<!-- DOM target where the WeatherBlox view will be rendered -->
<div id="wxblox"></div>

<script>
Aeris.wxblox.setAccess('CLIENT_KEY', 'CLIENT_SECRET');

// Insert view / layout code below

var view = new Aeris.wxblox.views.PlaceSearch('#wxblox');
view.load();

// End view / layout code </script>

Displays the place search field with a custom selection handler to redirect to a location's page:

var search = new Aeris.wxblox.views.PlaceSearch('#wxblox');
search.on(‘select’, function(e) {
var p = e.data.place;
var stateOrCountry = (p.place.state) ? p.place.state : p.place.country;
var url = locationPageUrl;
url = url.replace(/{{loc}}/, encodeURIComponent(p.place.name.toLowerCase() + ‘,’ + stateOrCountry.toLowerCase());
window.location.href = url;
});

Displays the primary place search field:

View not supported via API/server method

Displays the place search field with a custom selection handler to redirect to a location's page:

View not supported via API/server method

Displays the primary place search field:
View not supported via API/server method

Displays the place search field with a custom selection handler to redirect to a location's page:
View not supported via API/server method