Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ class ArrayField extends Component {
onBlur,
onFocus,
registry = getDefaultRegistry(),
rawErrors,
} = this.props;
const items = this.props.formData;
const { widgets, definitions, formContext } = registry;
Expand All @@ -455,6 +456,7 @@ class ArrayField extends Component {
readonly={readonly}
formContext={formContext}
autofocus={autofocus}
rawErrors={rawErrors}
/>
);
}
Expand All @@ -471,6 +473,7 @@ class ArrayField extends Component {
onBlur,
onFocus,
registry = getDefaultRegistry(),
rawErrors,
} = this.props;
const title = schema.title || name;
const items = this.props.formData;
Expand All @@ -492,6 +495,7 @@ class ArrayField extends Component {
readonly={readonly}
formContext={formContext}
autofocus={autofocus}
rawErrors={rawErrors}
/>
);
}
Expand Down Expand Up @@ -697,6 +701,7 @@ if (process.env.NODE_ENV !== "production") {
definitions: PropTypes.object.isRequired,
formContext: PropTypes.object.isRequired,
}),
rawErrors: PropTypes.arrayOf(PropTypes.string),
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/fields/BooleanField.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function BooleanField(props) {
readonly,
autofocus,
onChange,
rawErrors,
} = props;
const { title } = schema;
const { widgets, formContext } = registry;
Expand All @@ -44,6 +45,7 @@ function BooleanField(props) {
registry={registry}
formContext={formContext}
autofocus={autofocus}
rawErrors={rawErrors}
/>
);
}
Expand All @@ -67,6 +69,7 @@ if (process.env.NODE_ENV !== "production") {
definitions: PropTypes.object.isRequired,
formContext: PropTypes.object.isRequired,
}),
rawErrors: PropTypes.arrayOf(PropTypes.string),
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ function DefaultTemplate(props) {
<div className={classNames}>
{displayLabel && <Label label={label} required={required} id={id} />}
{displayLabel && description ? description : null}
{children}
{React.Children.map(children, child => {
return React.cloneElement(child, { rawErrors: props.rawErrors });
})}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit heavy. Why is this necessary? Wouldn't it be better to pass the rawErrors prop when we constructed widgets?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just reviewed the code again and I see that this can be passed through the SchemaFieldRender function. I'll update this.

{errors}
{help}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/fields/StringField.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function StringField(props) {
onBlur,
onFocus,
registry = getDefaultRegistry(),
rawErrors,
} = props;
const { title, format } = schema;
const { widgets, formContext } = registry;
Expand Down Expand Up @@ -51,6 +52,7 @@ function StringField(props) {
autofocus={autofocus}
registry={registry}
placeholder={placeholder}
rawErrors={rawErrors}
/>
);
}
Expand All @@ -77,6 +79,7 @@ if (process.env.NODE_ENV !== "production") {
disabled: PropTypes.bool,
readonly: PropTypes.bool,
autofocus: PropTypes.bool,
rawErrors: PropTypes.arrayOf(PropTypes.string),
};
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/widgets/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ function BaseInput(props) {
const _onChange = ({ target: { value } }) => {
return props.onChange(value === "" ? options.emptyValue : value);
};

const cleanProps = { ...inputProps };
delete cleanProps.rawErrors;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do const {rawErrors, ...cleanProps} = inputProps; See the "Rest in object destructuring section" of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring.


return (
<input
className="form-control"
readOnly={readonly}
disabled={disabled}
autoFocus={autofocus}
value={value == null ? "" : value}
{...inputProps}
{...cleanProps}
onChange={_onChange}
onBlur={onBlur && (event => onBlur(inputProps.id, event.target.value))}
onFocus={onFocus && (event => onFocus(inputProps.id, event.target.value))}
Expand Down