Merged two pull requests

This commit is contained in:
christianalfoni 2015-02-23 08:55:36 +01:00
parent bbc6ad38e2
commit 385263c383
9 changed files with 188 additions and 77 deletions

View File

@ -68,6 +68,10 @@ The main concept is that forms, inputs and validation is done very differently a
## <a name="changes">Changes</a>
**0.7.1**
- Fixed bug where external update of value on pristine form element did not update the form model (Thanks @sdemjanenko)
- Fixed bug where children are null/undefined (Thanks @sdemjanenko)
**0.7.0**
- Dynamic form elements. Add them at any point and they will be registered with the form
- **onChange()** handler is called whenever an form element has changed its value or a new form element is added to the form

View File

@ -1,6 +1,6 @@
{
"name": "formsy-react",
"version": "0.7.0",
"version": "0.7.1",
"main": "src/main.js",
"dependencies": {
"react": "^0.11.2"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "formsy-react",
"version": "0.7.0",
"version": "0.7.1",
"description": "A form input builder and validator for React JS",
"main": "src/main.js",
"scripts": {

View File

@ -162,6 +162,18 @@ Formsy.Mixin = {
nextProps._validate = this.props._validate;
},
componentDidUpdate: function(prevProps, prevState) {
// If the input is untouched and something outside changes the value
// update the FORM model by re-attaching to the form
if (this.state._isPristine) {
if (this.props.value !== prevProps.value && this.state._value === prevProps.value) {
this.state._value = this.props.value || '';
this.props._attachToForm(this);
}
}
},
// Detach it when component unmounts
componentWillUnmount: function () {
this.props._detachFromForm(this);
@ -353,13 +365,13 @@ Formsy.Form = React.createClass({displayName: "Form",
registerInputs: function (children) {
React.Children.forEach(children, function (child) {
if (child.props && child.props.name) {
if (child && child.props && child.props.name) {
child.props._attachToForm = this.attachToForm;
child.props._detachFromForm = this.detachFromForm;
child.props._validate = this.validate;
}
if (child.props && child.props.children) {
if (child && child.props && child.props.children) {
this.registerInputs(child.props.children);
}

File diff suppressed because one or more lines are too long

View File

@ -249,29 +249,23 @@ describe('Formsy', function () {
expect(isInvalid).toBe(false);
// Wait before adding the input
setTimeout(function () {
inputs.push(TestInput({
name: 'test2',
validations: 'isEmail',
value: 'foo@bar'
}));
inputs.push(TestInput({
name: 'test2',
validations: 'isEmail',
value: 'foo@bar'
}));
forceUpdate(function () {
forceUpdate(function () {
// Wait for next event loop, as that does the form
setTimeout(function () {
TestUtils.Simulate.submit(form.getDOMNode());
expect(isInvalid).toBe(true);
done();
}, 0);
// Wait for next event loop, as that does the form
setTimeout(function () {
TestUtils.Simulate.submit(form.getDOMNode());
expect(isInvalid).toBe(true);
done();
}, 0);
});
}, 10);
});
});
@ -349,23 +343,19 @@ describe('Formsy', function () {
);
// Wait before adding the input
setTimeout(function () {
inputs.push(TestInput({
name: 'test'
}));
inputs.push(TestInput({
name: 'test'
}));
forceUpdate(function () {
forceUpdate(function () {
// Wait for next event loop, as that does the form
setTimeout(function () {
expect(hasChanged).toHaveBeenCalled();
done();
}, 0);
// Wait for next event loop, as that does the form
setTimeout(function () {
expect(hasChanged).toHaveBeenCalled();
done();
}, 0);
});
}, 10);
});
});

View File

@ -161,6 +161,9 @@ Formsy.Mixin = {
},
componentDidUpdate: function(prevProps, prevState) {
// If the input is untouched and something outside changes the value
// update the FORM model by re-attaching to the form
if (this.state._isPristine) {
if (this.props.value !== prevProps.value && this.state._value === prevProps.value) {
this.state._value = this.props.value || '';