Skip to content

Commit

Permalink
releaser function better handles spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Sep 18, 2024
1 parent 70be02b commit fdbc3f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions assets/js/artifact-validate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ export function releaser(elm) {
throw new Error("The element of the releaser validator is null.");
}
elm.classList.remove("is-valid", "is-invalid");
// enforce uppercase
let value = elm.value.trim().toUpperCase();
// enforce uppercase and remove leading spaces
let value = elm.value.trimStart().toUpperCase();
// replace + with a comma and space for convenience
value = value.replace("+", ", ");
// valid characters were determined by this document,
// space, A-Z, À-Ö, Ø-Þ, 0-9, -, comma, &
value = value.replace(/[^ A-ZÀ-ÖØ-Þ0-9\-,&]/g, "");
// replace multiple spaces with a single space
value = value.replace(/[ ]{2,}/g, " ");
elm.value = value;

const min = elm.getAttribute("minlength");
Expand Down
2 changes: 2 additions & 0 deletions assets/js/editor-artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,13 @@ import { clipValue, getElmById, titleize } from "./helper.mjs";
throw new Error("The releaser 1 input is missing.");
}
rel1.addEventListener("input", (e) => validateReleaser(e.target));

const rel2 = document.getElementById("artifact-editor-releaser-2");
if (rel2 === null) {
throw new Error("The releaser 2 input is missing.");
}
rel2.addEventListener("input", (e) => validateReleaser(e.target));

const relUndo = document.getElementById("artifact-editor-releaser-undo");
if (relUndo === null) {
throw new Error("The releasers reset is missing.");
Expand Down
Loading

0 comments on commit fdbc3f7

Please sign in to comment.