(
path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>,
configOrLogic?:
| {when?: string | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>}
| string
| NoInfer<LogicFn<TValue, boolean | string, TPathKind>>,
)
| 40 | ): void; |
| 41 | |
| 42 | export function disabled<TValue, TPathKind extends PathKind = PathKind.Root>( |
| 43 | path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, |
| 44 | configOrLogic?: |
| 45 | | {when?: string | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>} |
| 46 | | string |
| 47 | | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>, |
| 48 | ): void { |
| 49 | assertPathIsCurrent(path); |
| 50 | |
| 51 | const pathNode = FieldPathNode.unwrapFieldPath(path); |
| 52 | |
| 53 | let logic: string | LogicFn<TValue, boolean | string, TPathKind> | undefined; |
| 54 | if (typeof configOrLogic === 'function' || typeof configOrLogic === 'string') { |
| 55 | logic = configOrLogic; |
| 56 | } else { |
| 57 | logic = configOrLogic?.when; |
| 58 | } |
| 59 | |
| 60 | pathNode.builder.addDisabledReasonRule((ctx) => { |
| 61 | let result: boolean | string = true; |
| 62 | if (typeof logic === 'string') { |
| 63 | result = logic; |
| 64 | } else if (logic) { |
| 65 | result = logic(ctx as FieldContext<TValue, TPathKind>); |
| 66 | } |
| 67 | if (typeof result === 'string') { |
| 68 | return {fieldTree: ctx.fieldTree, message: result}; |
| 69 | } |
| 70 | return result ? {fieldTree: ctx.fieldTree} : undefined; |
| 71 | }); |
| 72 | } |
searching dependent graphs…