Skip to content

Commit

Permalink
Fixed required bug
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Apr 15, 2015
1 parent 31a78c7 commit 1475dbb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "formsy-react",
"version": "0.12.2",
"version": "0.12.3",
"main": "src/main.js",
"dependencies": {
"react": "^0.13.1"
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "formsy-react",
"version": "0.12.2",
"version": "0.12.3",
"description": "A form input builder and validator for React JS",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion release/formsy-react.js
Expand Up @@ -243,7 +243,7 @@ Formsy.Form = React.createClass({displayName: "Form",
var isValid = !validationResults.failed.length && !(this.props.validationErrors && this.props.validationErrors[component.props.name]);
return {
isRequired: isRequired,
isValid: isValid,
isValid: isRequired ? false : isValid,
error: (function () {

if (isValid && !isRequired) {
Expand Down
2 changes: 1 addition & 1 deletion release/formsy-react.min.js

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions specs/Element-spec.js
Expand Up @@ -493,4 +493,30 @@ it('should allow an undefined value to be updated to a value', function (done) {
expect(inputComponent.getErrorMessage()).toBe('bar');
});

it('should not be valid if it is required and required rule is true', function () {
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
render: function () {
return <input value={this.getValue()}/>
}
});
var TestForm = React.createClass({
render: function () {
return (
<Formsy.Form>
<TestInput name="A"
required
/>
</Formsy.Form>
);
}
});
var form = TestUtils.renderIntoDocument(
<TestForm/>
);

var inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
expect(inputComponent.isValid()).toBe(false);
});

});
2 changes: 1 addition & 1 deletion src/main.js
Expand Up @@ -241,7 +241,7 @@ Formsy.Form = React.createClass({
var isValid = !validationResults.failed.length && !(this.props.validationErrors && this.props.validationErrors[component.props.name]);
return {
isRequired: isRequired,
isValid: isValid,
isValid: isRequired ? false : isValid,
error: (function () {

if (isValid && !isRequired) {
Expand Down

0 comments on commit 1475dbb

Please sign in to comment.