diff --git a/src/components/fields/BooleanField.js b/src/components/fields/BooleanField.js index 5531486283..8f10dccffb 100644 --- a/src/components/fields/BooleanField.js +++ b/src/components/fields/BooleanField.js @@ -21,6 +21,7 @@ function BooleanField(props) { readonly, autofocus, onChange, + rawErrors, } = props; const { title } = schema; const { widgets, formContext } = registry; @@ -44,6 +45,7 @@ function BooleanField(props) { registry={registry} formContext={formContext} autofocus={autofocus} + rawErrors={rawErrors} /> ); } @@ -67,6 +69,7 @@ if (process.env.NODE_ENV !== "production") { definitions: PropTypes.object.isRequired, formContext: PropTypes.object.isRequired, }), + rawErrors: PropTypes.arrayOf(PropTypes.string), }; } diff --git a/src/components/fields/SchemaField.js b/src/components/fields/SchemaField.js index e66299e1c4..105c7f325f 100644 --- a/src/components/fields/SchemaField.js +++ b/src/components/fields/SchemaField.js @@ -206,6 +206,7 @@ function SchemaFieldRender(props) { autofocus={autofocus} errorSchema={fieldErrorSchema} formContext={formContext} + rawErrors={__errors} /> ); diff --git a/src/components/fields/StringField.js b/src/components/fields/StringField.js index 9ecee6eb93..c2887e28e3 100644 --- a/src/components/fields/StringField.js +++ b/src/components/fields/StringField.js @@ -24,6 +24,7 @@ function StringField(props) { onBlur, onFocus, registry = getDefaultRegistry(), + rawErrors, } = props; const { title, format } = schema; const { widgets, formContext } = registry; @@ -51,6 +52,7 @@ function StringField(props) { autofocus={autofocus} registry={registry} placeholder={placeholder} + rawErrors={rawErrors} /> ); } @@ -77,6 +79,7 @@ if (process.env.NODE_ENV !== "production") { disabled: PropTypes.bool, readonly: PropTypes.bool, autofocus: PropTypes.bool, + rawErrors: PropTypes.arrayOf(PropTypes.string), }; } diff --git a/src/components/widgets/BaseInput.js b/src/components/widgets/BaseInput.js index 108b250d14..9a39e29678 100644 --- a/src/components/widgets/BaseInput.js +++ b/src/components/widgets/BaseInput.js @@ -22,6 +22,9 @@ function BaseInput(props) { const _onChange = ({ target: { value } }) => { return props.onChange(value === "" ? options.emptyValue : value); }; + + const { rawErrors, ...cleanProps } = inputProps; + return ( onBlur(inputProps.id, event.target.value))} onFocus={onFocus && (event => onFocus(inputProps.id, event.target.value))} diff --git a/test/SchemaField_test.js b/test/SchemaField_test.js index 3e94841b84..6376b4fd51 100644 --- a/test/SchemaField_test.js +++ b/test/SchemaField_test.js @@ -321,5 +321,25 @@ describe("SchemaField", () => { expect(matches).to.have.length.of(1); expect(matches[0].textContent).to.contain("test"); }); + + describe("Custom error rendering", () => { + const customStringWidget = props => { + return
{props.rawErrors}
; + }; + + it("should pass rawErrors down to custom widgets", () => { + const { node } = createFormComponent({ + schema, + uiSchema, + validate, + widgets: { BaseInput: customStringWidget }, + }); + submit(node); + + const matches = node.querySelectorAll(".custom-text-widget"); + expect(matches).to.have.length.of(1); + expect(matches[0].textContent).to.eql("test"); + }); + }); }); });