forked from errorstudio/openaddresses_form_old
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
115 lines (82 loc) · 4.65 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<title>Open Address Sorting Office</title>
<link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css"/>
<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico' />
<style>
body {
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<img src="assets/images/oa-logo-72.png" alt="Open Addresses logo"/>
<h1>Address Form as a Service</h1>
<p>This is an <em>address form as a service</em> widget from <a href="http://www.openaddressesuk.org">Open Addresses</a>.</p>
<p>The Open Addresses Sorting Office API will return well-formatted address data to your page, which you can handle as necessary. Your users can also submit their address to Open Addresses to improve accuracy.</p>
<h1>Demo</h1>
See the demo at <a href="https://alpha.openaddressesuk.org/services/free-format-address-input">https://alpha.openaddressesuk.org/services/free-format-address-input</a>.
<h1 id="toc_1">Prequisites</h1>
<p>There are a few prerequisites to using this widget:</p>
<ul>
<li>Javascript is required</li>
<li>You will need to hande the data which is returned, using Javascript</li>
</ul>
<h1 id="toc_2">Usage</h1>
<h2 id="toc_3">Basic Usage</h2>
<p>Include this code on your page - either in your <code><head></code> or at the bottom of the <code><body></code>:</p>
<pre><code><script type="text/javascript" async defer>
(function(config) {
var oa = document.createElement('script');
var config = (typeof(config) === 'undefined' ? {} : config);
oa.src = '//openaddressesuk.github.io/openaddresses_form/embed.js';
oa.type = 'text/javascript';
oa.async = 'true';
oa.onload = oa.onreadystatechange = function() {
var rs = this.readyState;
if (rs && rs != 'complete' && rs != 'loaded') return;
try { OpenAddresses.SortingOffice.embed(config); } catch (e) {}
};
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(oa, s);
})({
//your configuration options go here
});
</script></code></pre>
<p>And this html where you want to put the form:</p>
<pre><code><div id="openaddresses-form"></div></code></pre>
<h2 id="toc_4">Configuration Options</h2>
<pre><code>{
onLoading: function(data) {
// Do something with data being sent to Sorting Office
},
onError: function(message) {
// Do something with the error message
},
onSuccess: function(data) {
// Do something with the data returned from Sorting Office
},
embedInto: document.getElementById('your-id')[0]
}</code></pre>
<h3 id="toc_5">Callback Configuration</h3>
<p>If you use the script block at the start of this document, you'll get a form on your page, but you aren't handling the response from OpenAddresses. There are 3 callbacks you can configure in the options.</p>
<h4 id="toc_6"><code>onLoading</code></h4>
<p>The onLoading callback is called as soon as the call to Open Addresses starts, and includes the data being sent to Sorting Office.</p>
<h4 id="toc_7"><code>onError</code></h4>
<p>The onError callback is called whenever an error state is encountered, either before the form is submitted (because validation failed) or after Sorting Office returns an error.</p>
<h4 id="toc_8"> <code>onSuccess</code></h4>
<p>onSuccess is called when there's some useful data returned from OpenAddresses. See the <a href="https://github.com/OpenAddressesUK/sorting_office/blob/master/README.md">Sorting Office Documentation</a> for more details of the format.</p>
<h3 id="toc_9">Changing where to embed the form</h3>
<p>By default, the widget expects an HTML element with an ID of <code>openaddresses-form</code> to embed the form into.</p>
<p>You can change this by using the <code>embedInto</code> configuration option. Be sure to pass a DOM element into this, not a class or ID reference.</p>
<h1 id="toc_10">Advanced Usage</h1>
<p>There isn't any advanced usage yet :-) It might be possible to add more configuration options to change colours and things.</p>
</div>
</div>
</div>
</body>
</html>