Skip to content

Commit

Permalink
added ValidateFunction Type
Browse files Browse the repository at this point in the history
  • Loading branch information
morrys committed Nov 14, 2023
1 parent 6763d03 commit 5257a66
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "relay-forms",
"version": "2.1.0",
"version": "2.1.1",
"keywords": [
"forms",
"relay",
Expand Down
7 changes: 6 additions & 1 deletion src/RelayFormsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ export type FormSubmitReturn = {
reset: () => void;
};

export type ValidateFunction<ValueType> = (
value: ValueType,
deps?: { [key: string]: FormValueStateReturn<any> },
) => Promise<string | undefined> | string | undefined;

export type FormSetValueOptions<ValueType> = {
key: string;
initialValue?: ValueType;
validate?: (value: ValueType) => Promise<string | undefined> | string | undefined;
validate?: ValidateFunction<ValueType>;
validateOnChange?: boolean;
label?: string;
dependsOn?: ReadonlyArray<string> | null | undefined;
Expand Down
6 changes: 2 additions & 4 deletions src/useFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FormSetValueOptions,
FormSetValueReturn,
FormSetValueStateReturn,
ValidateFunction,
} from './RelayFormsTypes';
import { getSnapshot, getFieldId, commit } from './Utils';

Expand Down Expand Up @@ -60,10 +61,7 @@ function logicSetValue<ValueType>(params: LogicParams<ValueType>): LogicReturn<V
return deps;
}

function getValidate(): (
value: ValueType,
deps?: ReadonlyArray<any>,
) => Promise<string | undefined> | string | undefined {
function getValidate(): ValidateFunction<ValueType> {
return validate;
}
const ref = {
Expand Down

0 comments on commit 5257a66

Please sign in to comment.