hof 19.13.8 → 19.13.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/date/index.js +32 -23
- package/package.json +1 -1
package/components/date/index.js
CHANGED
@@ -60,6 +60,35 @@ module.exports = (key, opts) => {
|
|
60
60
|
dayOptional = true;
|
61
61
|
}
|
62
62
|
|
63
|
+
// take the 3 date parts, padding or defaulting
|
64
|
+
// to '01' if applic, then create a date value in the
|
65
|
+
// format YYYY-MM-DD. Save to req.body for processing
|
66
|
+
const preProcess = (req, res, next) => {
|
67
|
+
const parts = getParts(req.body, fields, key);
|
68
|
+
if (_.some(parts, part => part !== '')) {
|
69
|
+
if (dayOptional && parts.day === '') {
|
70
|
+
parts.day = '01';
|
71
|
+
} else {
|
72
|
+
parts.day = pad(parts.day);
|
73
|
+
}
|
74
|
+
if (monthOptional && parts.month === '') {
|
75
|
+
parts.month = '01';
|
76
|
+
} else {
|
77
|
+
parts.month = pad(parts.month);
|
78
|
+
}
|
79
|
+
req.body[key] = `${parts.year}-${parts.month}-${parts.day}`;
|
80
|
+
}
|
81
|
+
next();
|
82
|
+
};
|
83
|
+
|
84
|
+
// defaultFormatters on the base controller replace '--' with '-' on the process step.
|
85
|
+
// This ensures having the correct number of hyphens,
|
86
|
+
// so values do not jump from year to month when the page reloads.
|
87
|
+
const postProcess = (req, res, next) => {
|
88
|
+
req.form.values[key] = req.body[key];
|
89
|
+
next();
|
90
|
+
};
|
91
|
+
|
63
92
|
// if date field is included in errorValues, extend
|
64
93
|
// errorValues with the individual components
|
65
94
|
const preGetErrors = (req, res, next) => {
|
@@ -125,35 +154,15 @@ module.exports = (key, opts) => {
|
|
125
154
|
});
|
126
155
|
};
|
127
156
|
|
128
|
-
// take the 3 date parts, padding or defaulting
|
129
|
-
// to '01' if applic, then create a date value in the
|
130
|
-
// format YYYY-MM-DD. Save to req.body for processing
|
131
|
-
const preProcess = (req, res, next) => {
|
132
|
-
const parts = getParts(req.body, fields, key);
|
133
|
-
if (_.some(parts, part => part !== '')) {
|
134
|
-
if (dayOptional && parts.day === '') {
|
135
|
-
parts.day = '01';
|
136
|
-
} else {
|
137
|
-
parts.day = pad(parts.day);
|
138
|
-
}
|
139
|
-
if (monthOptional && parts.month === '') {
|
140
|
-
parts.month = '01';
|
141
|
-
} else {
|
142
|
-
parts.month = pad(parts.month);
|
143
|
-
}
|
144
|
-
req.body[key] = `${parts.year}-${parts.month}-${parts.day}`;
|
145
|
-
}
|
146
|
-
next();
|
147
|
-
};
|
148
|
-
|
149
157
|
// return config extended with hooks
|
150
158
|
return Object.assign({}, options, {
|
151
159
|
hooks: {
|
160
|
+
'pre-process': preProcess,
|
161
|
+
'post-process': postProcess,
|
152
162
|
'pre-getErrors': preGetErrors,
|
153
163
|
'post-getErrors': postGetErrors,
|
154
164
|
'post-getValues': postGetValues,
|
155
|
-
'pre-render': preRender
|
156
|
-
'pre-process': preProcess
|
165
|
+
'pre-render': preRender
|
157
166
|
}
|
158
167
|
});
|
159
168
|
};
|