@@ -47,6 +47,7 @@ export class JsonSchemaForm extends Component {
47
47
let { schema, errors, value, onChange, getComponent, fn, disabled } = this . props
48
48
const format = schema && schema . get ? schema . get ( "format" ) : null
49
49
const type = schema && schema . get ? schema . get ( "type" ) : null
50
+
50
51
let getComponentSilently = ( name ) => getComponent ( name , false , { failSilently : true } )
51
52
let Comp = type ? format ?
52
53
getComponentSilently ( `JsonSchema_${ type } _${ format } ` ) :
@@ -63,7 +64,7 @@ export class JsonSchema_string extends Component {
63
64
static propTypes = JsonSchemaPropShape
64
65
static defaultProps = JsonSchemaDefaultProps
65
66
onChange = ( e ) => {
66
- const value = this . props . schema && this . props . schema [ "type" ] === "file" ? e . target . files [ 0 ] : e . target . value
67
+ const value = this . props . schema && this . props . schema . get ( "type" ) === "file" ? e . target . files [ 0 ] : e . target . value
67
68
this . props . onChange ( value , this . props . keyName )
68
69
}
69
70
onEnumChange = ( val ) => this . props . onChange ( val )
@@ -92,23 +93,27 @@ export class JsonSchema_string extends Component {
92
93
const isDisabled = disabled || ( schemaIn && schemaIn === "formData" && ! ( "FormData" in window ) )
93
94
const Input = getComponent ( "Input" )
94
95
if ( type && type === "file" ) {
95
- return ( < Input type = "file"
96
- className = { errors . length ? "invalid" : "" }
97
- title = { errors . length ? errors : "" }
98
- onChange = { this . onChange }
99
- disabled = { isDisabled } /> )
96
+ return (
97
+ < Input type = "file"
98
+ className = { errors . length ? "invalid" : "" }
99
+ title = { errors . length ? errors : "" }
100
+ onChange = { this . onChange }
101
+ disabled = { isDisabled } />
102
+ )
100
103
}
101
104
else {
102
- return ( < DebounceInput
103
- type = { format && format === "password" ? "password" : "text" }
104
- className = { errors . length ? "invalid" : "" }
105
- title = { errors . length ? errors : "" }
106
- value = { value }
107
- minLength = { 0 }
108
- debounceTimeout = { 350 }
109
- placeholder = { description }
110
- onChange = { this . onChange }
111
- disabled = { isDisabled } /> )
105
+ return (
106
+ < DebounceInput
107
+ type = { format && format === "password" ? "password" : "text" }
108
+ className = { errors . length ? "invalid" : "" }
109
+ title = { errors . length ? errors : "" }
110
+ value = { value }
111
+ minLength = { 0 }
112
+ debounceTimeout = { 350 }
113
+ placeholder = { description }
114
+ onChange = { this . onChange }
115
+ disabled = { isDisabled } />
116
+ )
112
117
}
113
118
}
114
119
}
@@ -170,14 +175,15 @@ export class JsonSchema_array extends PureComponent {
170
175
const schemaItemsSchema = schema . getIn ( [ "items" , "schema" ] )
171
176
let ArrayItemsComponent
172
177
let isArrayItemText = false
178
+ let isArrayItemFile = schemaItemsType === "file" ? true : false
173
179
if ( schemaItemsType && schemaItemsFormat ) {
174
180
ArrayItemsComponent = getComponent ( `JsonSchema_${ schemaItemsType } _${ schemaItemsFormat } ` )
175
181
} else if ( schemaItemsType === "boolean" || schemaItemsType === "array" || schemaItemsType === "object" ) {
176
182
ArrayItemsComponent = getComponent ( `JsonSchema_${ schemaItemsType } ` )
177
183
}
178
184
// if ArrayItemsComponent not assigned or does not exist,
179
185
// use default schemaItemsType === "string" & JsonSchemaArrayItemText component
180
- if ( ! ArrayItemsComponent ) {
186
+ if ( ! ArrayItemsComponent && ! isArrayItemFile ) {
181
187
isArrayItemText = true
182
188
}
183
189
@@ -205,22 +211,30 @@ export class JsonSchema_array extends PureComponent {
205
211
return (
206
212
< div key = { i } className = "json-schema-form-item" >
207
213
{
208
- isArrayItemText ?
209
- < JsonSchemaArrayItemText
210
- value = { item }
211
- onChange = { ( val ) => this . onItemChange ( val , i ) }
212
- disabled = { disabled }
213
- errors = { errors }
214
- />
215
- : < ArrayItemsComponent { ...this . props }
216
- value = { item }
217
- onChange = { ( val ) => this . onItemChange ( val , i ) }
218
- disabled = { disabled }
219
- errors = { errors }
220
- schema = { schemaItemsSchema }
221
- getComponent = { getComponent }
222
- fn = { fn }
214
+ isArrayItemFile ?
215
+ < JsonSchemaArrayItemFile
216
+ value = { item }
217
+ onChange = { ( val ) => this . onItemChange ( val , i ) }
218
+ disabled = { disabled }
219
+ errors = { errors }
220
+ getComponent = { getComponent }
223
221
/>
222
+ : isArrayItemText ?
223
+ < JsonSchemaArrayItemText
224
+ value = { item }
225
+ onChange = { ( val ) => this . onItemChange ( val , i ) }
226
+ disabled = { disabled }
227
+ errors = { errors }
228
+ />
229
+ : < ArrayItemsComponent { ...this . props }
230
+ value = { item }
231
+ onChange = { ( val ) => this . onItemChange ( val , i ) }
232
+ disabled = { disabled }
233
+ errors = { errors }
234
+ schema = { schemaItemsSchema }
235
+ getComponent = { getComponent }
236
+ fn = { fn }
237
+ />
224
238
}
225
239
{ ! disabled ? (
226
240
< Button
@@ -275,6 +289,28 @@ export class JsonSchemaArrayItemText extends Component {
275
289
}
276
290
}
277
291
292
+ export class JsonSchemaArrayItemFile extends Component {
293
+ static propTypes = JsonSchemaPropShape
294
+ static defaultProps = JsonSchemaDefaultProps
295
+
296
+ onFileChange = ( e ) => {
297
+ const value = e . target . files [ 0 ]
298
+ this . props . onChange ( value , this . props . keyName )
299
+ }
300
+
301
+ render ( ) {
302
+ let { getComponent, errors, disabled } = this . props
303
+ const Input = getComponent ( "Input" )
304
+ const isDisabled = disabled || ! ( "FormData" in window )
305
+
306
+ return ( < Input type = "file"
307
+ className = { errors . length ? "invalid" : "" }
308
+ title = { errors . length ? errors : "" }
309
+ onChange = { this . onFileChange }
310
+ disabled = { isDisabled } /> )
311
+ }
312
+ }
313
+
278
314
export class JsonSchema_boolean extends Component {
279
315
static propTypes = JsonSchemaPropShape
280
316
static defaultProps = JsonSchemaDefaultProps
0 commit comments