Skip to content

Commit ee40769

Browse files
author
Christopher Whatley
committed
Cleanup? Help text, etc, but react fragments as help aren't working
1 parent d3ac2b1 commit ee40769

File tree

8 files changed

+37
-37
lines changed

8 files changed

+37
-37
lines changed

.dir-locals.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
((nil . ((eval . (add-to-list 'auto-mode-alist '("\\.js?\\'" . web-mode)))
1+
((nil . ((eval . (add-to-list 'auto-mode-alist '("\\.js?\\'" . rjsx-mode)))
22
(compile-command . "npm run-script build"))))

.eslintrc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
"node": true
2727
},
2828
"extends": "eslint:recommended",
29-
"ecmaFeatures": {
30-
"modules": true,
31-
"jsx": true,
32-
"experimentalObjectRestSpread": true
33-
},
3429
"plugins": [
3530
"jsx-a11y",
3631
"react"

src/FieldTemplate.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,36 @@
11
import { ADDITIONAL_PROPERTY_FLAG } from "react-jsonschema-form/lib/utils";
22
import React from "react";
3-
import {
4-
TextField,
5-
FormLabel,
6-
Typography,
7-
FormHelperText,
8-
} from "@material-ui/core";
3+
import { TextField, FormLabel, Typography } from "@material-ui/core";
94

105
export default function DefaultTemplate(props) {
116
const {
127
id,
138
label,
149
children,
15-
rawErrors,
16-
help,
1710
description,
1811
hidden,
1912
required,
2013
displayLabel,
2114
onKeyChange,
2215
schema,
23-
uiSchema,
2416
} = props;
2517
if (hidden) {
2618
return children;
2719
}
2820

29-
let help_text = uiSchema["ui:help"];
30-
let help_is_object = typeof help_text == "object";
31-
let actual_help = help;
32-
//console.log('help_text', typeof help_text, help_text)
33-
if (help_text && !help_is_object) {
34-
//console.log('replacing help', help_text);
35-
actual_help = (
36-
<Typography variant="caption" color="textSecondary">
37-
{help_text}
21+
function under_text(frag) {
22+
return (
23+
<Typography
24+
variant="caption"
25+
color="textSecondary"
26+
style={{ paddingLeft: "16px" }}>
27+
{frag}
3828
</Typography>
3929
);
40-
} else if (help_is_object) {
41-
actual_help = "";
4230
}
4331

4432
const additional = schema.hasOwnProperty(ADDITIONAL_PROPERTY_FLAG);
4533
const keyLabel = `${label} Key`;
46-
//console.log('schema', schema);
47-
//console.log('uiSchema', uiSchema);
4834

4935
function inner() {
5036
return (
@@ -62,10 +48,7 @@ export default function DefaultTemplate(props) {
6248
</React.Fragment>
6349
)}
6450
{children}
65-
{displayLabel && description ? description : null}
66-
{rawErrors &&
67-
rawErrors.map(e => <FormHelperText error={true}>{e}</FormHelperText>)}
68-
{actual_help}
51+
{displayLabel && description ? under_text(description) : null}
6952
</React.Fragment>
7053
);
7154
}

src/widgets/BaseInput.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ function BaseInput(props) {
2020
schema,
2121
formContext,
2222
registry,
23+
help,
24+
rawHelp,
2325
rawErrors,
26+
description,
27+
uiSchema,
2428
...inputProps
2529
} = props;
2630

@@ -37,6 +41,8 @@ function BaseInput(props) {
3741
disabled={disabled}
3842
autoFocus={autofocus}
3943
fullWidth={true}
44+
error={rawErrors && rawErrors.length > 0}
45+
helperText={rawErrors ? rawErrors.join(", ") : ""}
4046
variant="outlined"
4147
value={value == null ? "" : value}
4248
{...inputProps}

src/widgets/CheckboxWidget.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import DescriptionField from "../fields/DescriptionField.js";
4-
import { FormControlLabel, Checkbox } from "@material-ui/core";
4+
import {
5+
FormControl,
6+
FormControlLabel,
7+
FormHelperText,
8+
Checkbox,
9+
} from "@material-ui/core";
510

611
function CheckboxWidget(props) {
712
const {
@@ -12,12 +17,13 @@ function CheckboxWidget(props) {
1217
disabled,
1318
readonly,
1419
label,
20+
rawErrors,
1521
autofocus,
1622
onChange,
1723
} = props;
1824

1925
return (
20-
<React.Fragment>
26+
<FormControl error={!!rawErrors}>
2127
{schema.description && (
2228
<DescriptionField description={schema.description} />
2329
)}
@@ -35,7 +41,9 @@ function CheckboxWidget(props) {
3541
}
3642
label={label}
3743
/>
38-
</React.Fragment>
44+
{rawErrors &&
45+
rawErrors.map((e, i) => <FormHelperText key={i}>{e}</FormHelperText>)}
46+
</FormControl>
3947
);
4048
}
4149

src/widgets/CheckboxesWidget.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
FormControl,
55
FormLabel,
66
FormGroup,
7+
FormHelperText,
78
FormControlLabel,
89
Checkbox,
910
} from "@material-ui/core";
@@ -82,6 +83,8 @@ function CheckboxesWidget(props) {
8283
);
8384
})}
8485
</FormGroup>
86+
{rawErrors &&
87+
rawErrors.map((e, i) => <FormHelperText key={i}>{e}</FormHelperText>)}
8588
</FormControl>
8689
);
8790
}

src/widgets/RadioWidget.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
FormControl,
77
FormControlLabel,
88
FormLabel,
9+
FormHelperText,
910
} from "@material-ui/core";
1011

1112
function RadioWidget(props) {
@@ -36,7 +37,7 @@ function RadioWidget(props) {
3637
margin="dense"
3738
fullWidth={true}
3839
margin="normal"
39-
error={!!rawErrors}
40+
error={rawErrors && rawErrors.length}
4041
required={required}
4142
className={`rjsf-radio ` + classNames}
4243
style={{ paddingLeft: "16px" }}>
@@ -60,10 +61,11 @@ function RadioWidget(props) {
6061
autoFocus={autofocus && i === 0}
6162
/>
6263
);
63-
6464
return radio;
6565
})}
6666
</RadioGroup>
67+
{rawErrors &&
68+
rawErrors.map((e, i) => <FormHelperText key={i}>{e}</FormHelperText>)}
6769
</FormControl>
6870
);
6971
}

src/widgets/SelectWidget.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import ReactDOM from "react-dom";
33
import PropTypes from "prop-types";
44
import {
5+
FormHelperText,
56
FormControl,
67
MenuItem,
78
Select,
@@ -160,6 +161,8 @@ class SelectWidget extends React.Component {
160161
);
161162
})}
162163
</Select>
164+
{rawErrors &&
165+
rawErrors.map((e, i) => <FormHelperText key={i}>{e}</FormHelperText>)}
163166
</FormControl>
164167
);
165168
}

0 commit comments

Comments
 (0)