@@ -27,7 +27,10 @@ import { ErrorSchema, FieldValidation } from '@rjsf/utils';
|
||||
import React, { useCallback, useMemo, useState, type ReactNode } from 'react';
|
||||
import { NextFieldExtensionOptions } from '../../extensions';
|
||||
import { TemplateParameterSchema } from '../../../types';
|
||||
import { createAsyncValidators } from './createAsyncValidators';
|
||||
import {
|
||||
createAsyncValidators,
|
||||
type FormValidation,
|
||||
} from './createAsyncValidators';
|
||||
import { ReviewState, type ReviewStateProps } from '../ReviewState';
|
||||
import { useTemplateSchema } from '../../hooks/useTemplateSchema';
|
||||
import validator from '@rjsf/validator-ajv8';
|
||||
@@ -93,9 +96,7 @@ export const Stepper = (stepperProps: StepperProps) => {
|
||||
const [activeStep, setActiveStep] = useState(0);
|
||||
const [formState, setFormState] = useFormDataFromQuery(props.initialState);
|
||||
|
||||
const [errors, setErrors] = useState<
|
||||
undefined | Record<string, FieldValidation>
|
||||
>();
|
||||
const [errors, setErrors] = useState<undefined | FormValidation>();
|
||||
const styles = useStyles();
|
||||
|
||||
const extensions = useMemo(() => {
|
||||
|
||||
@@ -25,7 +25,10 @@ function isObject(value: JsonValue | undefined): value is JsonObject {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
type FormValidation = Record<
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type FormValidation = Record<
|
||||
string,
|
||||
FieldValidation | Record<string, FieldValidation>
|
||||
>;
|
||||
@@ -41,7 +44,7 @@ export const createAsyncValidators = (
|
||||
formData: JsonObject,
|
||||
pathPrefix: string = '#',
|
||||
current: JsonObject = formData,
|
||||
): Promise<Record<string, FieldValidation>> {
|
||||
): Promise<FormValidation> {
|
||||
const parsedSchema = new JSONSchema(rootSchema);
|
||||
const formValidation: FormValidation = {};
|
||||
|
||||
@@ -68,7 +71,7 @@ export const createAsyncValidators = (
|
||||
}
|
||||
}
|
||||
|
||||
return formValidation as Record<string, FieldValidation>;
|
||||
return formValidation;
|
||||
}
|
||||
|
||||
return async (formData: JsonObject) => {
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import type { FieldValidation } from '@rjsf/utils';
|
||||
import { FormValidation } from './createAsyncValidators';
|
||||
|
||||
function isFieldValidation(error: any): error is FieldValidation {
|
||||
return !!error && '__errors' in error;
|
||||
}
|
||||
|
||||
export function hasErrors(errors?: Record<string, FieldValidation>): boolean {
|
||||
export function hasErrors(errors?: FormValidation): boolean {
|
||||
if (!errors) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user