type progress to Elements

This commit is contained in:
James
2020-12-01 08:04:31 -05:00
parent 8c8c49c66d
commit dc8ffa34e4
18 changed files with 52 additions and 79 deletions

View File

@@ -4,11 +4,13 @@ import { Fields, Field, Data } from './types';
const buildValidationPromise = async (fieldState: Field, field: FieldSchema) => {
const validatedFieldState = fieldState;
validatedFieldState.valid = typeof field.validate === 'function' ? await field.validate(fieldState.value, field) : true;
const validationResult = typeof field.validate === 'function' ? await field.validate(fieldState.value, field) : true;
if (typeof validatedFieldState.valid === 'string') {
validatedFieldState.errorMessage = validatedFieldState.valid;
if (typeof validationResult === 'string') {
validatedFieldState.errorMessage = validationResult;
validatedFieldState.valid = false;
} else {
validatedFieldState.valid = true;
}
};
@@ -86,7 +88,7 @@ const buildStateFromSchema = async (fieldSchema: FieldSchema[], fullData: Data =
}
// Handle non-array-based nested fields (group, etc)
if (field.type === 'row' || field.type === 'group') {
if (field.type === 'group') {
const subFieldData = initialData?.[field.name] as Data;
return {
@@ -102,7 +104,7 @@ const buildStateFromSchema = async (fieldSchema: FieldSchema[], fullData: Data =
}
// Handle field types that do not use names (row, etc)
if (field.type === 'row' || field.type === 'group') {
if (field.type === 'row') {
return {
...state,
...iterateFields(field.fields, data, path),