-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 1.19 KB
/
index.js
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
const addressParts = require('./lib/addressParts');
module.exports = {
extend: 'apostrophe-forms-base-field-widgets',
label: 'Google Address',
beforeConstruct (self, options) {
require('./lib/schema')(options, addressParts);
},
afterConstruct (self) {
require('./lib/migrations')(self, addressParts);
},
construct (self, options) {
const superLoad = self.load;
self.load = function(req, widgets, callback) {
return superLoad(req, widgets, function(err) {
if (err) {
return callback(err);
}
self.addGoogleApiKey(req);
return callback(null);
});
};
self.addGoogleApiKey = function (req) {
req.data.googleApiKey = options.googleApiKey;
};
self.sanitizeFormField = function (req, form, widget, input, output) {
const parts = Object.keys(widget.addressParts);
if (widget.splitAddress && parts && parts.length) {
for (const addressPart of parts) {
output[`${widget.fieldName}-${addressPart}`] = self.apos.launder.string(input[`${widget.fieldName}-${addressPart}`]);
}
}
output[widget.fieldName] = self.apos.launder.string(input[widget.fieldName]);
};
}
};