Skip to content

Commit

Permalink
merged #50
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosRasic committed May 22, 2018
2 parents 957d7e6 + 42dbcfb commit ab91b0b
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 78 deletions.
26 changes: 13 additions & 13 deletions lib/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,23 @@ exports.default = function (Component) {
value: function render() {
var innerRef = this.props.innerRef;

var propsForElement = _extends({
getErrorMessage: this.getErrorMessage,
getErrorMessages: this.getErrorMessages,
getValue: this.getValue,
hasValue: this.hasValue,
isFormDisabled: this.isFormDisabled,
isValid: this.isValid,
isPristine: this.isPristine,
isFormSubmitted: this.isFormSubmitted,
isRequired: this.isRequired,
var propsForElement = _extends({}, this.props, {
errorMessage: this.getErrorMessage(),
errorMessages: this.getErrorMessages(),
hasValue: this.hasValue(),
isFormDisabled: this.isFormDisabled(),
isFormSubmitted: this.isFormSubmitted(),
isPristine: this.isPristine(),
isRequired: this.isRequired(),
isValid: this.isValid(),
isValidValue: this.isValidValue,
resetValue: this.resetValue,
setValidations: this.setValidations,
setValue: this.setValue,
showRequired: this.showRequired,
showError: this.showError
}, this.props);
showError: this.showError(),
showRequired: this.showRequired(),
value: this.getValue()
});

if (innerRef) {
propsForElement.ref = innerRef;
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.

24 changes: 12 additions & 12 deletions src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,22 @@ export default (Component) => {
render() {
const { innerRef } = this.props;
const propsForElement = {
getErrorMessage: this.getErrorMessage,
getErrorMessages: this.getErrorMessages,
getValue: this.getValue,
hasValue: this.hasValue,
isFormDisabled: this.isFormDisabled,
isValid: this.isValid,
isPristine: this.isPristine,
isFormSubmitted: this.isFormSubmitted,
isRequired: this.isRequired,
...this.props,
errorMessage: this.getErrorMessage(),
errorMessages: this.getErrorMessages(),
hasValue: this.hasValue(),
isFormDisabled: this.isFormDisabled(),
isFormSubmitted: this.isFormSubmitted(),
isPristine: this.isPristine(),
isRequired: this.isRequired(),
isValid: this.isValid(),
isValidValue: this.isValidValue,
resetValue: this.resetValue,
setValidations: this.setValidations,
setValue: this.setValue,
showRequired: this.showRequired,
showError: this.showError,
...this.props,
showError: this.showError(),
showRequired: this.showRequired(),
value: this.getValue(),
};

if (innerRef) {
Expand Down
53 changes: 21 additions & 32 deletions tests/Element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import immediate from './utils/immediate';

export default {

'should return passed and setValue() value when using getValue()': function (test) {
'should pass down correct value prop after using setValue()': function (test) {

const form = TestUtils.renderIntoDocument(
<Formsy>
Expand All @@ -33,7 +33,7 @@ export default {
this.props.setValue(event.target.value, false);
}
render() {
return <input type="text" value={this.props.getValue()} onChange={this.updateValue}/>;
return <input type="text" value={this.props.value} onChange={this.updateValue}/>;
}
})
const form = TestUtils.renderIntoDocument(
Expand All @@ -60,7 +60,7 @@ export default {
this.props.setValue(event.target.value, false);
}
render() {
return <input type="text" value={this.props.getValue()} onChange={this.updateValue}/>;
return <input type="text" value={this.props.value} onChange={this.updateValue}/>;
}
})
const form = TestUtils.renderIntoDocument(
Expand Down Expand Up @@ -105,10 +105,10 @@ export default {

'should return error message passed when calling getErrorMessage()': function (test) {

let getErrorMessage = null;
let errorMessage = null;
const Input = InputFactory({
componentDidMount: function() {
getErrorMessage = this.props.getErrorMessage;
errorMessage = this.props.errorMessage;
}
});
TestUtils.renderIntoDocument(
Expand All @@ -117,7 +117,7 @@ export default {
</Formsy>
);

test.equal(getErrorMessage(), 'Has to be email');
test.equal(errorMessage, 'Has to be email');

test.done();

Expand All @@ -127,8 +127,8 @@ export default {

let isValid = null;
const Input = InputFactory({
componentDidMount: function() {
isValid = this.props.isValid;
componentWillReceiveProps: function(nextProps) {
isValid = nextProps.isValid;
}
});
const form = TestUtils.renderIntoDocument(
Expand All @@ -137,10 +137,10 @@ export default {
</Formsy>
);

test.equal(isValid(), false);
test.equal(isValid, false);
const input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
TestUtils.Simulate.change(input, {target: {value: '[email protected]'}});
test.equal(isValid(), true);
test.equal(isValid, true);

test.done();

Expand All @@ -162,9 +162,9 @@ export default {
</Formsy>
);

test.equal(isRequireds[0](), false);
test.equal(isRequireds[1](), true);
test.equal(isRequireds[2](), true);
test.equal(isRequireds[0], false);
test.equal(isRequireds[1], true);
test.equal(isRequireds[2], true);

test.done();

Expand All @@ -186,9 +186,9 @@ export default {
</Formsy>
);

test.equal(showRequireds[0](), false);
test.equal(showRequireds[1](), true);
test.equal(showRequireds[2](), false);
test.equal(showRequireds[0], false);
test.equal(showRequireds[1], true);
test.equal(showRequireds[2], false);

test.done();

Expand All @@ -198,8 +198,8 @@ export default {

let isPristine = null;
const Input = InputFactory({
componentDidMount: function() {
isPristine = this.props.isPristine;
componentWillReceiveProps: function(nextProps) {
isPristine = nextProps.isPristine;
}
});
const form = TestUtils.renderIntoDocument(
Expand All @@ -208,10 +208,10 @@ export default {
</Formsy>
);

test.equal(isPristine(), true);
test.equal(isPristine, true);
const input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
TestUtils.Simulate.change(input, {target: {value: 'foo'}});
test.equal(isPristine(), false);
test.equal(isPristine, false);

test.done();

Expand Down Expand Up @@ -594,7 +594,7 @@ export default {
shouldComponentUpdate: function() { return false },
render: function() {
renderSpy();
return <input type={this.props.type} value={this.props.getValue()} onChange={this.updateValue}/>;
return <input type={this.props.type} value={this.props.value} onChange={this.updateValue}/>;
}
});

Expand All @@ -613,21 +613,10 @@ export default {
'binds all necessary methods': function (test) {
const onInputRef = input => {
[
'getErrorMessage',
'getErrorMessages',
'getValue',
'hasValue',
'isFormDisabled',
'isValid',
'isPristine',
'isFormSubmitted',
'isRequired',
'isValidValue',
'resetValue',
'setValidations',
'setValue',
'showRequired',
'showError',
].forEach(fnName => {
const fn = input[fnName];
try {
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-equals-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render: function() {
return <input value={this.props.getValue()} readOnly />;
return <input value={this.props.value} readOnly />;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isAlpha-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render: function() {
return <input value={this.props.getValue()} readOnly />;
return <input value={this.props.value} readOnly />;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isAlphanumeric-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isEmail-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isEmptyString-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isExisty-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isFloat-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isInt-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isLength-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isNumeric-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isUrl-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-isWords-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-maxLength-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Rules-minLength-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InputFactory } from './utils/TestInput';

const TestInput = InputFactory({
render() {
return <input value={this.props.getValue()} readOnly/>;
return <input value={this.props.value} readOnly/>;
}
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Validation-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MyTest extends React.Component {
}

render() {
return <input type={this.props.type} value={this.props.getValue()} onChange={this.handleChange}/>;
return <input type={this.props.type} value={this.props.value} onChange={this.handleChange}/>;
}
}
const FormsyTest = withFormsy(MyTest);
Expand Down Expand Up @@ -125,7 +125,7 @@ export default {
let isValid = false;
const CustomInput = InputFactory({
componentDidMount: function() {
isValid = this.props.isValid();
isValid = this.props.isValid;
}
});
const form = TestUtils.renderIntoDocument(
Expand Down
4 changes: 2 additions & 2 deletions tests/ValidationDeprecated-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MyTest extends React.Component {
}

render() {
return <input type={this.props.type} value={this.props.getValue()} onChange={this.handleChange}/>;
return <input type={this.props.type} value={this.props.value} onChange={this.handleChange}/>;
}
}
const FormsyTest = Wrapper(MyTest);
Expand Down Expand Up @@ -108,7 +108,7 @@ export default {
let isValid = false;
const CustomInput = InputFactory({
componentDidMount: function() {
isValid = this.props.isValid();
isValid = this.props.isValid;
}
});
const form = TestUtils.renderIntoDocument(
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/TestInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestInput extends React.Component {
}

render() {
return <input type={this.props.type} value={this.props.getValue()} onChange={this.updateValue}/>;
return <input type={this.props.type} value={this.props.value} onChange={this.updateValue}/>;
}
}

Expand Down

0 comments on commit ab91b0b

Please sign in to comment.