Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing #123 #124

Merged
merged 5 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ exports.default = function (Component) {
};

WrappedComponent.defaultProps = {
innerRef: function innerRef() {},
innerRef: null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes the build, which is currently broken here.

required: false,
validationError: '',
validationErrors: {},
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ var Formsy = function (_React$Component) {
}

if (isRequired) {
var error = validationErrors[requiredResults.success[0]];
var error = validationErrors[requiredResults.success[0]] || validationError;
return error ? [error] : null;
}

Expand Down
2 changes: 1 addition & 1 deletion release/formsy-react.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/formsy-react.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export default (Component) => {
};

WrappedComponent.defaultProps = {
innerRef: null,
required: false,
validationError: '',
validationErrors: {},
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Formsy extends React.Component {
}

if (isRequired) {
const error = validationErrors[requiredResults.success[0]];
const error = validationErrors[requiredResults.success[0]] || validationError;
return error ? [error] : null;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/Element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,30 @@ export default {

},

'should return the validationError if the field is invalid and required rule is true': function (test) {

class TestForm extends React.Component {
render() {
return (
<Formsy>
<TestInput name="A"
validationError='Field is required'
required
/>
</Formsy>
);
}
}
const form = TestUtils.renderIntoDocument(<TestForm/>);

const inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
test.equal(inputComponent.isValid(), false);
test.equal(inputComponent.getErrorMessage(), 'Field is required');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the above change this will fail


test.done();

},

'should handle objects and arrays as values': function (test) {

class TestForm extends React.Component {
Expand Down