@@ -888,7 +888,7 @@ function FormInput(_ref) {
888888 required : props . required
889889 } ) , /*#__PURE__*/ React__default [ "default" ] . createElement ( "div" , {
890890 className : error ? "rjf-input-group has-error" : "rjf-input-group"
891- } , /*#__PURE__*/ React__default [ "default" ] . createElement ( "input" , props ) , error && error . map ( ( error , i ) => /*#__PURE__*/ React__default [ "default" ] . createElement ( "span" , {
891+ } , props . children || /*#__PURE__*/ React__default [ "default" ] . createElement ( "input" , props ) , error && error . map ( ( error , i ) => /*#__PURE__*/ React__default [ "default" ] . createElement ( "span" , {
892892 className : "rjf-error-text" ,
893893 key : i
894894 } , error ) ) , help_text && /*#__PURE__*/ React__default [ "default" ] . createElement ( "span" , {
@@ -950,6 +950,7 @@ function FormRadioInput(_ref3) {
950950 }
951951
952952 return /*#__PURE__*/ React__default [ "default" ] . createElement ( "label" , {
953+ className : "rjf-radio-option" ,
953954 key : title + '_' + inputValue + '_' + i
954955 } , /*#__PURE__*/ React__default [ "default" ] . createElement ( "input" , _extends ( { } , props , {
955956 value : inputValue ,
@@ -1065,15 +1066,15 @@ class FormMultiSelectInput extends React__default["default"].Component {
10651066 className : "rjf-multiselect-field"
10661067 } , /*#__PURE__*/ React__default [ "default" ] . createElement ( FormInput , {
10671068 label : this . props . label ,
1068- type : "text" ,
1069- value : this . props . value . length ? this . props . value . length + ' selected' : 'Select...' ,
10701069 help_text : this . props . help_text ,
1071- error : this . props . error ,
1072- onClick : this . toggleOptions ,
1073- readOnly : true ,
1070+ error : this . props . error
1071+ } , /*#__PURE__*/ React__default [ "default" ] . createElement ( FormMultiSelectInputField , {
10741072 inputRef : this . input ,
1075- className : "rjf-multiselect-field-input"
1076- } ) , this . state . showOptions && /*#__PURE__*/ React__default [ "default" ] . createElement ( FormMultiSelectInputOptions , {
1073+ onClick : this . toggleOptions ,
1074+ value : this . props . value ,
1075+ onChange : this . handleChange ,
1076+ disabled : this . props . readOnly
1077+ } ) ) , this . state . showOptions && /*#__PURE__*/ React__default [ "default" ] . createElement ( FormMultiSelectInputOptions , {
10771078 options : this . props . options ,
10781079 value : this . props . value ,
10791080 hideOptions : this . hideOptions ,
@@ -1087,6 +1088,43 @@ class FormMultiSelectInput extends React__default["default"].Component {
10871088
10881089}
10891090
1091+ class FormMultiSelectInputField extends React__default [ "default" ] . Component {
1092+ constructor ( ...args ) {
1093+ super ( ...args ) ;
1094+
1095+ this . handleRemove = ( e , index ) => {
1096+ e . stopPropagation ( ) ; // we create a fake event object for the onChange handler
1097+
1098+ let event = {
1099+ target : {
1100+ value : this . props . value [ index ] ,
1101+ checket : false
1102+ }
1103+ } ;
1104+ this . props . onChange ( event ) ;
1105+ } ;
1106+ }
1107+
1108+ render ( ) {
1109+ return /*#__PURE__*/ React__default [ "default" ] . createElement ( "div" , {
1110+ className : "rjf-multiselect-field-input" ,
1111+ onClick : this . props . onClick ,
1112+ ref : this . props . inputRef ,
1113+ tabIndex : 0
1114+ } , this . props . value . length ? this . props . value . map ( ( item , index ) => /*#__PURE__*/ React__default [ "default" ] . createElement ( "span" , {
1115+ className : "rjf-multiselect-field-input-item" ,
1116+ key : item + '_' + index
1117+ } , /*#__PURE__*/ React__default [ "default" ] . createElement ( "span" , null , item ) , this . props . disabled || /*#__PURE__*/ React__default [ "default" ] . createElement ( "button" , {
1118+ title : "Remove" ,
1119+ type : "button" ,
1120+ onClick : e => this . handleRemove ( e , index )
1121+ } , "\xD7" ) ) ) : /*#__PURE__*/ React__default [ "default" ] . createElement ( "span" , {
1122+ className : "rjf-multiselect-field-input-placeholder"
1123+ } , "Select..." ) ) ;
1124+ }
1125+
1126+ }
1127+
10901128class FormMultiSelectInputOptions extends React__default [ "default" ] . Component {
10911129 constructor ( ...args ) {
10921130 super ( ...args ) ;
@@ -2545,12 +2583,13 @@ function getArrayFormRow(args) {
25452583 } = args ;
25462584 let rows = [ ] ;
25472585 let groups = [ ] ;
2586+ let isReadonly = getKeyword ( schema , 'readonly' , 'readOnly' , false ) ;
25482587 let removable = true ;
25492588 let min_items = getKeyword ( schema , 'min_items' , 'minItems' ) || 0 ;
2550- if ( data . length <= min_items ) removable = false ;
2589+ if ( data . length <= min_items || isReadonly ) removable = false ;
25512590 let addable = true ;
25522591 let max_items = getKeyword ( schema , 'max_items' , 'maxItems' ) || 100 ;
2553- if ( data . length >= max_items ) addable = false ;
2592+ if ( data . length >= max_items || isReadonly ) addable = false ;
25542593 let isRef = schema . items . hasOwnProperty ( '$ref' ) ;
25552594 if ( isRef ) schema . items = args . getRef ( schema . items [ '$ref' ] ) ;
25562595 let type = normalizeKeyword ( schema . items . type ) ;
@@ -2568,6 +2607,7 @@ function getArrayFormRow(args) {
25682607 getRef : args . getRef ,
25692608 errorMap : args . errorMap
25702609 } ;
2610+ if ( isReadonly ) nextArgs . schema . readOnly = true ;
25712611
25722612 if ( nextArgs . schema . widget === 'multiselect' ) {
25732613 nextArgs . data = data ;
@@ -2581,8 +2621,8 @@ function getArrayFormRow(args) {
25812621 for ( let i = 0 ; i < data . length ; i ++ ) {
25822622 nextArgs . data = data [ i ] ;
25832623 nextArgs . name = joinCoords ( name , i ) ;
2584- if ( i === 0 ) nextArgs . onMoveUp = null ; else nextArgs . onMoveUp = e => onMove ( joinCoords ( name , i ) , joinCoords ( name , i - 1 ) ) ;
2585- if ( i === data . length - 1 ) nextArgs . onMoveDown = null ; else nextArgs . onMoveDown = e => onMove ( joinCoords ( name , i ) , joinCoords ( name , i + 1 ) ) ;
2624+ if ( i === 0 || isReadonly ) nextArgs . onMoveUp = null ; else nextArgs . onMoveUp = e => onMove ( joinCoords ( name , i ) , joinCoords ( name , i - 1 ) ) ;
2625+ if ( i === data . length - 1 || isReadonly ) nextArgs . onMoveDown = null ; else nextArgs . onMoveDown = e => onMove ( joinCoords ( name , i ) , joinCoords ( name , i + 1 ) ) ;
25862626
25872627 if ( type === 'array' ) {
25882628 groups . push ( getArrayFormRow ( nextArgs ) ) ;
@@ -2612,6 +2652,13 @@ function getArrayFormRow(args) {
26122652 let coords = name ; // coordinates for insertion and deletion
26132653
26142654 if ( rows . length || ! rows . length && ! groups . length ) {
2655+ let rowError ;
2656+
2657+ if ( ! groups . length ) {
2658+ rowError = args . errorMap [ getCoordsFromName ( coords ) ] ;
2659+ if ( typeof rowError === 'string' ) rowError = [ rowError ] ;
2660+ }
2661+
26152662 rows = /*#__PURE__*/ React__default [ "default" ] . createElement ( FormGroup , {
26162663 level : level ,
26172664 schema : schema ,
@@ -2620,7 +2667,10 @@ function getArrayFormRow(args) {
26202667 editable : args . editable ,
26212668 onEdit : args . onKeyEdit ,
26222669 key : 'row_group_' + name
2623- } , rows ) ;
2670+ } , rowError && rowError . map ( ( error , i ) => /*#__PURE__*/ React__default [ "default" ] . createElement ( "div" , {
2671+ className : "rjf-error-text" ,
2672+ key : i
2673+ } , error ) ) , rows ) ;
26242674
26252675 if ( args . parentType === 'object' && args . removable ) {
26262676 rows = /*#__PURE__*/ React__default [ "default" ] . createElement ( "div" , {
@@ -2632,10 +2682,9 @@ function getArrayFormRow(args) {
26322682 }
26332683 }
26342684
2635- let groupError = args . errorMap [ getCoordsFromName ( coords ) ] ;
2636- if ( typeof groupError === 'string' ) groupError = [ groupError ] ;
2637-
26382685 if ( groups . length ) {
2686+ let groupError = args . errorMap [ getCoordsFromName ( coords ) ] ;
2687+ if ( typeof groupError === 'string' ) groupError = [ groupError ] ;
26392688 let groupTitle = schema . title ? /*#__PURE__*/ React__default [ "default" ] . createElement ( GroupTitle , {
26402689 editable : args . editable ,
26412690 onEdit : args . onKeyEdit
@@ -2657,8 +2706,8 @@ function getArrayFormRow(args) {
26572706 key : 'group_wrapper_' + name + '_' + index
26582707 } , /*#__PURE__*/ React__default [ "default" ] . createElement ( FormRowControls , {
26592708 onRemove : removable ? e => onRemove ( joinCoords ( name , index ) ) : null ,
2660- onMoveUp : index > 0 ? e => onMove ( joinCoords ( name , index ) , joinCoords ( name , index - 1 ) ) : null ,
2661- onMoveDown : index < groups . length - 1 ? e => onMove ( joinCoords ( name , index ) , joinCoords ( name , index + 1 ) ) : null
2709+ onMoveUp : index > 0 && ! isReadonly ? e => onMove ( joinCoords ( name , index ) , joinCoords ( name , index - 1 ) ) : null ,
2710+ onMoveDown : index < groups . length - 1 && ! isReadonly ? e => onMove ( joinCoords ( name , index ) , joinCoords ( name , index + 1 ) ) : null
26622711 } ) , i ) ) , addable && /*#__PURE__*/ React__default [ "default" ] . createElement ( Button , {
26632712 className : "add" ,
26642713 onClick : e => onAdd ( getBlankData ( schema . items , args . getRef ) , coords ) ,
@@ -2681,6 +2730,7 @@ function getObjectFormRow(args) {
26812730 level
26822731 } = args ;
26832732 let rows = [ ] ;
2733+ let isReadonly = getKeyword ( schema , 'readonly' , 'readOnly' , false ) ;
26842734 let schema_keys = getKeyword ( schema , 'keys' , 'properties' , { } ) ;
26852735
26862736 if ( schema . hasOwnProperty ( 'allOf' ) ) {
@@ -2708,6 +2758,7 @@ function getObjectFormRow(args) {
27082758
27092759 let isRef = schemaValue . hasOwnProperty ( '$ref' ) ;
27102760 if ( isRef ) schemaValue = args . getRef ( schemaValue [ '$ref' ] ) ;
2761+ if ( isReadonly ) schemaValue . readOnly = true ;
27112762 let type = normalizeKeyword ( schemaValue . type ) ;
27122763
27132764 if ( ! schemaValue . title ) {
@@ -2788,7 +2839,7 @@ function getObjectFormRow(args) {
27882839 rows = /*#__PURE__*/ React__default [ "default" ] . createElement ( FormGroup , {
27892840 level : level ,
27902841 schema : schema ,
2791- addable : schema . additionalProperties ,
2842+ addable : schema . additionalProperties && ! isReadonly ,
27922843 onAdd : ( ) => handleKeyValueAdd ( data , coords , onAdd , schema . additionalProperties , args . getRef ) ,
27932844 editable : args . editable ,
27942845 onEdit : args . onKeyEdit ,
@@ -3597,6 +3648,7 @@ class ReactJSONForm extends React__default["default"].Component {
35973648 getRef : this . getRef ,
35983649 errorMap : this . props . errorMap || { }
35993650 } ;
3651+ if ( this . props . readonly ) args . schema . readOnly = true ;
36003652 if ( type === 'array' ) return getArrayFormRow ( args ) ; else if ( type === 'object' ) return getObjectFormRow ( args ) ; else if ( type === 'oneOf' ) return getOneOfFormRow ( args ) ; else if ( type === 'anyOf' ) return getAnyOfFormRow ( args ) ; else if ( type === 'allOf' ) return getAllOfFormRow ( args ) ;
36013653 return formGroups ;
36023654 } ;
@@ -4055,6 +4107,7 @@ function FormInstance(config) {
40554107 this . errorMap = config . errorMap ;
40564108 this . fileHandler = config . fileHandler ;
40574109 this . fileHandlerArgs = config . fileHandlerArgs || { } ;
4110+ this . readonly = config . readonly || false ;
40584111 this . eventListeners = null ;
40594112 this . _dataSynced = false ;
40604113
@@ -4089,7 +4142,8 @@ function FormInstance(config) {
40894142 errorMap : this . errorMap ,
40904143 fileHandler : this . fileHandler ,
40914144 fileHandlerArgs : this . fileHandlerArgs ,
4092- onChange : this . onChange
4145+ onChange : this . onChange ,
4146+ readonly : this . readonly
40934147 } ) , document . getElementById ( this . containerId ) ) ;
40944148 } catch ( error ) {
40954149 ReactDOM__default [ "default" ] . render ( /*#__PURE__*/ React__default [ "default" ] . createElement ( ErrorReporter , {
@@ -4188,7 +4242,8 @@ class FormContainer extends React__default["default"].Component {
41884242 onChange : this . handleChange ,
41894243 fileHandler : this . props . fileHandler ,
41904244 fileHandlerArgs : this . props . fileHandlerArgs ,
4191- errorMap : this . props . errorMap
4245+ errorMap : this . props . errorMap ,
4246+ readonly : this . props . readonly
41924247 } ) ;
41934248 }
41944249
0 commit comments