-
Notifications
You must be signed in to change notification settings - Fork 14
/
change.js
31 lines (23 loc) · 896 Bytes
/
change.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
var extend = require('xtend')
var getFormData = require('form-data-set/element')
var BaseEvent = require('./base-event.js')
var VALID_CHANGE = ['checkbox', 'file', 'select-multiple', 'select-one'];
var VALID_INPUT = ['color', 'date', 'datetime', 'datetime-local', 'email',
'month', 'number', 'password', 'range', 'search', 'tel', 'text', 'time',
'url', 'week', 'textarea'];
module.exports = BaseEvent(changeLambda);
function changeLambda(ev, broadcast) {
var target = ev.target
var isValid =
(ev.type === 'input' && VALID_INPUT.indexOf(target.type) !== -1) ||
(ev.type === 'change' && VALID_CHANGE.indexOf(target.type) !== -1);
if (!isValid) {
if (ev.startPropagation) {
ev.startPropagation()
}
return
}
var value = getFormData(ev.currentTarget)
var data = extend(value, this.data)
broadcast(data)
}