The UI component of the AiteStory project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
712 B

  1. document.addEventListener("DOMContentLoaded", function() {
  2. var inputDate = document.querySelector("form input[name=\"fictionalDate\"]")
  3. var pError = document.querySelector("form p.red")
  4. if (inputDate.value != "") {
  5. inputDate.value = new Date(inputDate.value).toDateString().substring(4)
  6. }
  7. document.querySelector("form").onsubmit = function(ev) {
  8. console.log(inputDate.value)
  9. var date = new Date(inputDate.value + " UTC")
  10. if (Number.isNaN(date.getTime())) {
  11. date = new Date(inputDate.value)
  12. if (Number.isNaN(date.getTime())) {
  13. pError.innerHTML = "Invalid date"
  14. return false
  15. }
  16. }
  17. inputDate.value = date.toISOString()
  18. return true
  19. }
  20. })