|
|
@@ -304,6 +304,61 @@
|
|
|
return ['1', 'on', 'true', true, 1].includes(value);
|
|
|
}
|
|
|
|
|
|
+ function parseBirthdateParts(value) {
|
|
|
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value || '').trim());
|
|
|
+ if (!match) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ const year = Number(match[1]);
|
|
|
+ const month = Number(match[2]);
|
|
|
+ const day = Number(match[3]);
|
|
|
+ const candidate = new Date(Date.UTC(year, month - 1, day));
|
|
|
+ if (
|
|
|
+ Number.isNaN(candidate.getTime()) ||
|
|
|
+ candidate.getUTCFullYear() !== year ||
|
|
|
+ candidate.getUTCMonth() !== month - 1 ||
|
|
|
+ candidate.getUTCDate() !== day
|
|
|
+ ) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return { year, month, day };
|
|
|
+ }
|
|
|
+
|
|
|
+ function deriveAdultFlagFromBirthdate(birthdateValue) {
|
|
|
+ const parts = parseBirthdateParts(birthdateValue);
|
|
|
+ if (!parts) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ const now = new Date();
|
|
|
+ const yearNow = now.getFullYear();
|
|
|
+ const monthNow = now.getMonth() + 1;
|
|
|
+ const dayNow = now.getDate();
|
|
|
+ const isFutureBirthdate =
|
|
|
+ parts.year > yearNow ||
|
|
|
+ (parts.year === yearNow && (parts.month > monthNow || (parts.month === monthNow && parts.day > dayNow)));
|
|
|
+ if (isFutureBirthdate) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ let age = yearNow - parts.year;
|
|
|
+ const hadBirthdayThisYear = monthNow > parts.month || (monthNow === parts.month && dayNow >= parts.day);
|
|
|
+ if (!hadBirthdayThisYear) {
|
|
|
+ age -= 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return age >= 18 ? '1' : '0';
|
|
|
+ }
|
|
|
+
|
|
|
+ function addComputedAgeFlags(data) {
|
|
|
+ const adultFlag = deriveAdultFlagFromBirthdate(data.geburtsdatum || '');
|
|
|
+ data.is_adult = adultFlag;
|
|
|
+ data.is_minor = adultFlag === '' ? '' : adultFlag === '1' ? '0' : '1';
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
function collectCurrentFormData() {
|
|
|
const data = {};
|
|
|
|
|
|
@@ -324,7 +379,7 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- return data;
|
|
|
+ return addComputedAgeFlags(data);
|
|
|
}
|
|
|
|
|
|
function evaluateFieldRule(rule, formData) {
|