Browse Source

Fixed validation of fictionalDate input in add/edit story.

master
Gisle Aune 6 years ago
parent
commit
40259b8839
  1. 2
      marko/page/story-content/components/edit-chapter-modal/component.js
  2. 8
      marko/page/story-content/components/edit-story-modal/component.js
  3. 8
      marko/page/story/components/add-story-modal/component.js

2
marko/page/story-content/components/edit-chapter-modal/component.js

@ -25,6 +25,8 @@ module.exports = class {
if (fictionalDate != null) {
fictionalDate = moment.utc(fictionalDate).format("MMM D, YYYY")
} else {
fictionalDate = ""
}
this.state.values = {fictionalDate, title, source, commentMode, commentsLocked}

8
marko/page/story-content/components/edit-story-modal/component.js

@ -46,8 +46,12 @@ module.exports = class {
let fictionalDate = new Date(values.fictionalDate + " UTC")
if (values.fictionalDate != "") {
if (Number.isNaN(fictionalDate)) {
this.state.error = `Could not parse ${values.fictionalDate} as date`
if (Number.isNaN(fictionalDate.getTime())) {
this.state.error = `Could not parse ${values.fictionalDate} as date.`
if (values.fictionalDate.includes("th")) {
this.state.error += " Try to remove the 'th'."
}
return
}
} else {

8
marko/page/story/components/add-story-modal/component.js

@ -42,8 +42,12 @@ module.exports = class {
let fictionalDate = new Date(values.fictionalDate + " UTC")
if (values.fictionalDate != "") {
if (Number.isNaN(fictionalDate)) {
this.state.error = `Could not parse ${values.fictionalDate} as date`
if (Number.isNaN(fictionalDate.getTime())) {
this.state.error = `Could not parse ${values.fictionalDate} as date.`
if (values.fictionalDate.includes("th")) {
this.state.error += " Try to remove the 'th'."
}
return
}
} else {

Loading…
Cancel
Save