File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ export const RJSFForm = (props: FormProps) => (
39
39
...templates ,
40
40
...props . templates ,
41
41
} }
42
+ formContext = { props . formData }
42
43
widgets = { { ...widgets , ...props . widgets } }
43
44
translateString = { translateString }
44
45
/>
Original file line number Diff line number Diff line change 16
16
17
17
import { ObjectFieldTemplateProps , canExpand , titleId } from '@rjsf/utils'
18
18
import { JSONPath } from 'jsonpath-plus'
19
+ import { convertJSONPointerToJSONPath } from '@Common/Helper'
19
20
import { FieldRowWithLabel } from '../common/FieldRow'
20
21
import { TitleField } from './TitleField'
21
22
import { AddButton } from './ButtonTemplates'
@@ -33,6 +34,7 @@ const Field = ({
33
34
schema,
34
35
title,
35
36
uiSchema,
37
+ formContext,
36
38
} : ObjectFieldTemplateProps < any , RJSFFormSchema , any > ) => {
37
39
const hasAdditionalProperties = ! ! schema . additionalProperties
38
40
@@ -54,8 +56,19 @@ const Field = ({
54
56
return true
55
57
}
56
58
try {
57
- const value = JSONPath ( { path : hiddenSchemaProp . match , json : formData } ) ?. [ 0 ]
58
- const isHidden = value === undefined || hiddenSchemaProp . condition === value
59
+ if ( ! hiddenSchemaProp . path ) {
60
+ throw new Error ( 'Empty path element' )
61
+ }
62
+ let path = ''
63
+ if ( hiddenSchemaProp . path . match ( / ^ \w + ( \/ \w + ) * $ / g) && hiddenSchemaProp . path . charAt ( 0 ) !== '/' ) {
64
+ path = convertJSONPointerToJSONPath ( `/${ hiddenSchemaProp . path } ` )
65
+ }
66
+ // NOTE: formContext is the formData passed to RJSFForm
67
+ const value = JSONPath ( {
68
+ path,
69
+ json : formContext ,
70
+ } ) ?. [ 0 ]
71
+ const isHidden = value === undefined || hiddenSchemaProp . value === value
59
72
return ! isHidden
60
73
} catch {
61
74
return true
Original file line number Diff line number Diff line change @@ -21,8 +21,8 @@ import { StrictRJSFSchema } from '@rjsf/utils'
21
21
export type FormProps = Omit < ComponentProps < typeof RJSFForm > , 'validator' >
22
22
23
23
interface Hidden {
24
- condition : boolean
25
- match : string
24
+ value : boolean
25
+ path : string
26
26
}
27
27
28
28
export interface RJSFFormSchema extends StrictRJSFSchema {
You can’t perform that action at this time.
0 commit comments