forked from Meteor-Community-Packages/meteor-autoform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoform-inputs.js
95 lines (95 loc) · 2.32 KB
/
autoform-inputs.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
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
// Default Handlers
defaultInputValueHandlers = {
'select.autoform-boolean': function () {
var val = this.val();
if (val === "true") {
return true;
} else if (val === "false") {
return false;
}
},
'select[multiple]': function () {
return Utility.getSelectValues(this[0]);
},
'select': function () {
return this.val();
},
'input.autoform-boolean[type=checkbox]': function () {
// boolean checkbox
return this.is(":checked");
},
'input.autoform-array-item[type=checkbox]': function () {
// array checkbox
if (this.is(":checked")) {
return this.val();
}
},
'input.autoform-boolean[type=radio]': function () {
//boolean radio
var val = this.val();
if (this.is(":checked")) {
if (val === "true") {
return true;
} else if (val === "false") {
return false;
}
}
},
'input[type=radio]': function () {
if (this.is(":checked")) {
return this.val();
}
},
'input.autoform-boolean[type=hidden]': function () {
// type overridden to hidden, but schema expects boolean
var val = this.val();
if (val === "true") {
return true;
} else if (val === "false") {
return false;
}
},
'[type=select]': function () {
return Utility.maybeNum(this.val());
},
'input[type=date]': function () {
var val = this.val();
if (Utility.isValidDateString(val)) {
//Date constructor will interpret val as UTC and create
//date at mignight in the morning of val date in UTC time zone
return new Date(val);
} else {
return null;
}
},
'input[type=datetime]': function () {
var val = this.val();
val = (typeof val === "string") ? val.replace(/ /g, "T") : val;
if (Utility.isValidNormalizedForcedUtcGlobalDateAndTimeString(val)) {
//Date constructor will interpret val as UTC due to ending "Z"
return new Date(val);
} else {
return null;
}
},
'input[type=datetime-local]': function () {
var val = this.val();
val = (typeof val === "string") ? val.replace(/ /g, "T") : val;
var offset = this.attr("data-offset") || "Z";
if (Utility.isValidNormalizedLocalDateAndTimeString(val)) {
return new Date(val + offset);
} else {
return null;
}
},
'[contenteditable]': function () {
return this.html();
},
'[data-null-value]': function () {
return null;
},
'[data-schema-key]': function () {
// fallback
return this.val();
}
};