Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Fix removed future time validation; fixes #536, #528
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikuoja committed Apr 23, 2020
1 parent bf85d2b commit 16b9e33
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"validation-requiredAtId": "This field is required",
"validation-requiredString": "This field is required",
"validation-requiredStringForCourses": "This field is required",
"validation-defaultEndInTheFuture": "The start time must be in the future if end time is not specified",
"validation-afterStartTime": "The end time must be later than start time",
"validation-afterStartTimeAndInFuture": "The end time must be in the future and later than the start time",
"validation-afterEnrolmentStartTime": "The end time must be later than start time",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@
"validation-afterStartTime": "Päättymisajan pitää olla alkamisaikaa myöhemmin",
"validation-afterStartTimeAndInFuture": "Päättymisajan pitää olla tulevaisuudessa ja alkamisaikaa myöhemmin",
"validation-afterEnrolmentStartTime": "Päättymisajan pitää olla alkamisaikaa myöhemmin",
"validation-inTheFuture": "Tapahtuman pitää olla tulevaisuudessa",
"validation-defaultEndInTheFuture": "Alkamisajan pitää olla tulevaisuudessa, jos päättymisaikaa ei tunneta",
"validation-inTheFuture": "Päättymisajan pitää olla tulevaisuudessa",
"validation-stringLimitReached": "Tämä kenttä voi olla korkeintaan {limit} merkkiä pitkä",
"validation-stringLengthCounter": "{counter} merkkiä jäljellä",
"validation-longStringLengthCounter": " merkkiä käytetty",
Expand Down
4 changes: 3 additions & 1 deletion src/validation/validationRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ var validations = {
return validations.matchRegexp(values, value, /(24((:|\.)00)?)|^((2[0-3]|1[0-9]|0[0-9]|[0-9])((:|\.)[0-5][0-9])?)$/i);
},
isDate(values, value) {
return moment(value, moment.ISO_8601, true).isValid()
// Emtpy string needs to match, to allow empty *or* valid date.
// Required (non-empty) fields are validated separately.
return !value | moment(value, moment.ISO_8601, true).isValid()
},
afterStartTime: function afterStartTime(values, value) {
if (!values.start_time || !value) return true
Expand Down
8 changes: 4 additions & 4 deletions src/validation/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const draftValidations = {
const publicValidations = {
name: [VALIDATION_RULES.REQUIRE_MULTI, VALIDATION_RULES.REQUIRED_IN_CONTENT_LANGUAGE],
location: [VALIDATION_RULES.REQUIRE_AT_ID],
start_time: [VALIDATION_RULES.REQUIRED_STRING, VALIDATION_RULES.IS_DATE], // Datetime is saved as ISO string
end_time: [VALIDATION_RULES.AFTER_START_TIME, VALIDATION_RULES.IN_THE_FUTURE],
start_time: [VALIDATION_RULES.REQUIRED_STRING, VALIDATION_RULES.IS_DATE, VALIDATION_RULES.DEFAULT_END_IN_FUTURE], // Datetime is saved as ISO string
end_time: [VALIDATION_RULES.AFTER_START_TIME, VALIDATION_RULES.IS_DATE, VALIDATION_RULES.IN_THE_FUTURE],
price: [VALIDATION_RULES.HAS_PRICE],
short_description: [VALIDATION_RULES.REQUIRE_MULTI, VALIDATION_RULES.REQUIRED_IN_CONTENT_LANGUAGE, VALIDATION_RULES.SHORT_STRING],
description: [VALIDATION_RULES.REQUIRE_MULTI, VALIDATION_RULES.REQUIRED_IN_CONTENT_LANGUAGE, VALIDATION_RULES.LONG_STRING],
Expand All @@ -49,8 +49,8 @@ const publicValidations = {
extlink_twitter: [VALIDATION_RULES.IS_URL],
extlink_instagram: [VALIDATION_RULES.IS_URL],
sub_events: {
start_time: [VALIDATION_RULES.REQUIRED_STRING, VALIDATION_RULES.IS_DATE],
end_time: [VALIDATION_RULES.AFTER_START_TIME, VALIDATION_RULES.IN_THE_FUTURE],
start_time: [VALIDATION_RULES.REQUIRED_STRING, VALIDATION_RULES.IS_DATE, VALIDATION_RULES.DEFAULT_END_IN_FUTURE],
end_time: [VALIDATION_RULES.AFTER_START_TIME, VALIDATION_RULES.IS_DATE, VALIDATION_RULES.IN_THE_FUTURE],
},
keywords: [VALIDATION_RULES.AT_LEAST_ONE_MAIN_CATEGORY],
audience_min_age: [VALIDATION_RULES.IS_INT],
Expand Down

0 comments on commit 16b9e33

Please sign in to comment.