Use new common error handling in CreateEditCollectionScene

This commit is contained in:
Max Berger
2026-03-09 23:35:56 +01:00
parent b9179871c4
commit 6d7396395f
2 changed files with 57 additions and 28 deletions

View File

@@ -16,7 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { COLOR_RE } from "../constants.js";
import { ErrorHandler } from "./error.js";
import { isValidHREF } from "./misc.js";
/**
* Manages form validation by running validation functions on input fields.
@@ -74,7 +76,44 @@ export function validate_non_empty(input, field_name) {
return field_name + " is empty";
};
}
/**
* Validates that the input is a valid HREF.
* @param {HTMLInputElement} input
* @param {string} field_name
* @returns {function(): ?string}
*/
export function validate_href(input, field_name) {
return () => {
let value = input.value.trim();
if (!value) {
return field_name + " is empty";
}
if (value.startsWith("/")) {
return field_name + " cannot start with /";
}
if (!isValidHREF(value)) {
return field_name + " is invalid";
}
return null;
};
}
/**
* Validates that the input is a valid color.
* @param {HTMLInputElement} input
* @param {string} field_name
* @returns {function(): ?string}
*/
export function validate_color(input, field_name) {
return () => {
let value = input.value.trim();
if (!value) {
return null;
}
if (!COLOR_RE.exec(value)) {
return field_name + " is invalid";
}
return null;
};
}