Skip to content

Commit

Permalink
Fixing #123 (#124)
Browse files Browse the repository at this point in the history
* Fixing linting issues

* Fixing issue where validationError wasn't appearing on when the field was required

* Updating lib and release

* Adding semicolons to fix lint issues

* Slightly cleaner solution
  • Loading branch information
TheMcMurder authored and MilosRasic committed Oct 31, 2018
1 parent 3284327 commit 1c5cc12
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
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,
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');

test.done();

},

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

class TestForm extends React.Component {
Expand Down

0 comments on commit 1c5cc12

Please sign in to comment.