Skip to content

Commit

Permalink
updated core fn check
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekelly881 committed May 29, 2024
1 parent 4143ec6 commit 982fc83
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/react/effect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@effect/schema": "^0.67.13",
"@tanstack/effect-form-adapter": "workspace:^",
"@tanstack/react-form": "^0.20.0",
"@tanstack/react-form": "workspace:^0.20.2",
"effect": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/effect-form-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"peerDependencies": {
"@effect/schema": "^0.67.13",
"@effect/schema": "^0.67.14",
"effect": "^3.2.5"
},
"repository": "tanstack/form",
Expand Down Expand Up @@ -58,4 +58,4 @@
"@effect/schema": "^0.67.14",
"effect": "^3.2.5"
}
}
}
1 change: 0 additions & 1 deletion packages/effect-form-adapter/src/validator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Schema from '@effect/schema/Schema'
import * as ArrayFormatter from '@effect/schema/ArrayFormatter'
import * as Effect from 'effect/Effect'
import * as Either from 'effect/Either'
import * as Exit from 'effect/Exit'
import * as Layer from 'effect/Layer'
import * as ManagedRuntime from 'effect/ManagedRuntime'
Expand Down
11 changes: 10 additions & 1 deletion packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import type {
import type { AsyncValidator, SyncValidator, Updater } from './utils'
import type { DeepKeys, DeepValue, NoInfer } from './util-types'

function is_constructor(f: any) {
try {
Reflect.construct(String, [], f);
} catch (e) {
return false;
}
return true;
}

export type FieldValidateFn<
TParentData,
TName extends DeepKeys<TParentData>,
Expand Down Expand Up @@ -350,7 +359,7 @@ export class FieldApi<
this.options.validatorAdapter,
] as const
for (const adapter of adapters) {
if (adapter && typeof props.validate !== 'function') {
if (adapter && is_constructor(props.validate)) {
return adapter()[props.type](
props.value as never,
props.validate,
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 982fc83

Please sign in to comment.