Skip to content

Commit 980e07b

Browse files
committed
Add support for readonly inputs
1 parent 6a269d5 commit 980e07b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/components/form.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function FormInput({label, help_text, error, inputRef, ...props}) {
1111
if (inputRef)
1212
props.ref = inputRef;
1313

14-
if (props.type === 'number' && props.value === null)
14+
if (props.value === null)
1515
props.value = '';
1616

1717
return (
@@ -37,6 +37,9 @@ export function FormCheckInput({label, help_text, error, value, ...props}) {
3737
if (props.checked === '' || props.checked === null || props.checked === undefined)
3838
props.checked = false
3939

40+
if (props.readOnly)
41+
props.disabled = true;
42+
4043
return (
4144
<div>
4245
<label><input {...props} /> {label}</label>
@@ -46,6 +49,9 @@ export function FormCheckInput({label, help_text, error, value, ...props}) {
4649

4750

4851
export function FormRadioInput({label, help_text, error, value, options, ...props}) {
52+
if (props.readOnly)
53+
props.disabled = true;
54+
4955
return (
5056
<div>
5157
<label>{label}</label>
@@ -73,6 +79,9 @@ export function FormRadioInput({label, help_text, error, value, options, ...prop
7379

7480

7581
export function FormSelectInput({label, help_text, error, value, options, ...props}) {
82+
if (props.readOnly)
83+
props.disabled = true;
84+
7685
return (
7786
<div>
7887
{label && <label>{label}</label>}
@@ -268,6 +277,10 @@ export class FormFileInput extends React.Component {
268277
props.type = 'file';
269278
props.onChange = this.handleChange;
270279

280+
if (props.readOnly)
281+
props.disabled = true;
282+
283+
271284
return (
272285
<div>
273286
{label && <label>{label}</label>}

src/ui.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function FormField(props) {
3535
let inputProps = {
3636
name: props.name,
3737
value: props.data,
38+
readOnly: props.schema.readOnly,
3839
};
3940

4041
let type = props.schema.type;

0 commit comments

Comments
 (0)