Added coercing system to field configuration, revised some of the data validation errors

This commit is contained in:
2026-04-09 19:17:57 +02:00
parent a088f97e2e
commit 31b6eecdec
3 changed files with 62 additions and 16 deletions

View File

@@ -6,11 +6,26 @@ function mandatory_anything(value) {
}
const fc = new Field_Configuration('Some_Field', mandatory_anything, 'Anything defined');
function string_coercion_function(value) {
if (value === undefined) {
throw new Error('Undefined not allowed');
}
return String(value);
}
const fc = new Field_Configuration('Some_Field', null, string_coercion_function, 'Anything that could be a string');
console.log(fc.check_validation(undefined));
console.log(fc.check_validation(true));
console.log([ fc.coerce(123) ]);
console.log([ fc.coerce(true) ]);
console.log([ fc.load(undefined, 'Some configuration') ]);
console.log([ fc.load(true) ]);
//fc.validate(undefined);
fc.validate(undefined, 'New thingamabob object');
console.log(fc.load(undefined, 'New thingamabob object'));