File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import {
73
73
isVisible ,
74
74
Resolve ,
75
75
resolveSchema ,
76
+ decode ,
76
77
} from '../util' ;
77
78
import {
78
79
Translator ,
@@ -114,7 +115,7 @@ const isRequired = (
114
115
rootSchema : JsonSchema
115
116
) : boolean => {
116
117
const pathSegments = schemaPath . split ( '/' ) ;
117
- const lastSegment = pathSegments [ pathSegments . length - 1 ] ;
118
+ const lastSegment = decode ( pathSegments [ pathSegments . length - 1 ] ) ;
118
119
// Skip "properties", "items" etc. to resolve the parent
119
120
const nextHigherSchemaSegments = pathSegments . slice (
120
121
0 ,
Original file line number Diff line number Diff line change @@ -1871,6 +1871,38 @@ test('mapStateToControlProps - i18n errors - custom keyword wins over all other
1871
1871
t . is ( props . errors , 'this is my error custom error message' ) ;
1872
1872
} ) ;
1873
1873
1874
+ test ( 'mapStateToControlProps - required is calculated correctly from encoded JSON Pointer' , ( t ) => {
1875
+ const uischema : ControlElement = {
1876
+ type : 'Control' ,
1877
+ scope : '#/properties/~1firstName' ,
1878
+ } ;
1879
+ const schema = {
1880
+ type : 'object' ,
1881
+ properties : {
1882
+ '/firstName' : { type : 'string' } ,
1883
+ } ,
1884
+ required : [ '/firstName' ] ,
1885
+ } ;
1886
+ const ownProps = {
1887
+ visible : true ,
1888
+ uischema,
1889
+ path : 'foo' ,
1890
+ schema,
1891
+ } ;
1892
+ const state = {
1893
+ jsonforms : {
1894
+ core : {
1895
+ schema,
1896
+ data : { } ,
1897
+ uischema,
1898
+ errors : [ ] as ErrorObject [ ] ,
1899
+ } ,
1900
+ } ,
1901
+ } ;
1902
+ const props = mapStateToControlProps ( state , ownProps ) ;
1903
+ t . true ( props . required === true ) ;
1904
+ } ) ;
1905
+
1874
1906
test ( 'mapStateToEnumControlProps - i18n - should not crash without i18n' , ( t ) => {
1875
1907
const ownProps = {
1876
1908
uischema : coreUISchema ,
You can’t perform that action at this time.
0 commit comments