Browse Source

Fixed ordinal checker crashing edit story form.

master
Gisle Aune 5 years ago
parent
commit
3cbe42e1ba
  1. 10
      marko/page/story-content/components/edit-story-modal/component.js

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

@ -2,6 +2,8 @@ const moment = require("moment")
const {storyApi} = require("../../../../../rpdata/api/Story")
const ORDINAL_REGEX = /[0-9]{1,2}(st|nd|rd|th)/g
module.exports = class {
onCreate() {
this.state = {
@ -45,11 +47,13 @@ module.exports = class {
const values = this.state.values
let fictionalDate = new Date(values.fictionalDate + " UTC")
if (values.fictionalDate != "") {
if (values.fictionalDate) {
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'."
const ordinal = values.fictionalDate.match(ORDINAL_REGEX)[0]
if (ordinal != null) {
this.state.error += " Try to remove the '"+ordinal.slice(-2)+"'."
}
return

Loading…
Cancel
Save