Fixed value bug and configured deploy new version script
This commit is contained in:
parent
6b696d8f03
commit
8acaeadaee
|
|
@ -1,3 +1,3 @@
|
|||
.DS_Store
|
||||
build/
|
||||
build
|
||||
node_modules
|
||||
|
|
|
|||
38
API.md
38
API.md
|
|
@ -11,6 +11,7 @@
|
|||
- [onValidSubmit()](#onvalidsubmit)
|
||||
- [onInvalidSubmit()](#oninvalidsubmit)
|
||||
- [onChange()](#onchange)
|
||||
- [resetForm()](#resetform)
|
||||
- [Formsy.Mixin](#formsymixin)
|
||||
- [name](#name)
|
||||
- [value](#value)
|
||||
|
|
@ -30,6 +31,7 @@
|
|||
- [showError()](#showerror)
|
||||
- [isPristine()](#ispristine)
|
||||
- [isFormDisabled()](#isformdisabled)
|
||||
- [isFormSubmitted()](#isFormSubmitted)
|
||||
- [validate](#validate)
|
||||
- [formNoValidate](#formnovalidate)
|
||||
- [Formsy.addValidationRule](#formsyaddvalidationrule)
|
||||
|
|
@ -140,6 +142,23 @@ Triggers when form is submitted with an invalid state. The arguments are the sam
|
|||
```
|
||||
"onChange" triggers when setValue is called on your form elements. It is also triggered when dynamic form elements have been added to the form. The "currentValues" is an object where the key is the name of the input and the value is the current value.
|
||||
|
||||
#### <a name="onchange">resetForm()</a>
|
||||
```html
|
||||
var MyForm = React.createClass({
|
||||
resetForm: function () {
|
||||
this.refs.form.reset();
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<Formsy.Form ref="form">
|
||||
...
|
||||
</Formsy.Form>
|
||||
);
|
||||
}
|
||||
});
|
||||
```
|
||||
Manually reset the form to its pristine state.
|
||||
|
||||
### <a name="formsymixin">Formsy.Mixin</a>
|
||||
|
||||
#### <a name="name">name</a>
|
||||
|
|
@ -427,7 +446,7 @@ By default all formsy input elements are pristine, which means they are not "tou
|
|||
|
||||
**note!** When the form is reset, using the resetForm callback function on for example [**onSubmit**](#onsubmitdata-resetform-invalidateform) the inputs are reset to their pristine state.
|
||||
|
||||
#### <a name="ispristine">isFormDisabled()</a>
|
||||
#### <a name="isformdisabled">isFormDisabled()</a>
|
||||
```javascript
|
||||
var MyInput = React.createClass({
|
||||
mixins: [Formsy.Mixin],
|
||||
|
|
@ -444,6 +463,23 @@ React.render(<Formy.Form disabled={true}/>);
|
|||
```
|
||||
You can now disable the form itself with a prop and use **isFormDisabled()** inside form elements to verify this prop.
|
||||
|
||||
#### <a name="isformsubmitted">isFormSubmitted()</a>
|
||||
```javascript
|
||||
var MyInput = React.createClass({
|
||||
mixins: [Formsy.Mixin],
|
||||
render: function () {
|
||||
var error = this.isFormSubmitted() ? this.getErrorMessage() : null;
|
||||
return (
|
||||
<div>
|
||||
<input type="text" value={this.getValue()}/>
|
||||
{error}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
```
|
||||
You can check if the form has been submitted.
|
||||
|
||||
#### <a name="validate">validate</a>
|
||||
```javascript
|
||||
var MyInput = React.createClass({
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
"start": "webpack-dev-server --content-base build",
|
||||
"deploy": "NODE_ENV=production webpack -p --config webpack.production.config.js",
|
||||
"test": "node testrunner",
|
||||
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples"
|
||||
},
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -481,4 +481,41 @@ it('should allow an undefined value to be updated to a value', function (done) {
|
|||
expect(inputComponent.isValid()).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle objects and arrays as values', function () {
|
||||
|
||||
var TestInput = React.createClass({
|
||||
mixins: [Formsy.Mixin],
|
||||
render: function () {
|
||||
return <div>{JSON.stringify(this.getValue())}</div>
|
||||
}
|
||||
});
|
||||
var TestForm = React.createClass({
|
||||
getInitialState: function () {
|
||||
return {
|
||||
foo: {foo: 'bar'},
|
||||
bar: ['foo']
|
||||
};
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<Formsy.Form>
|
||||
<TestInput name="foo" value={this.state.foo}/>
|
||||
<TestInput name="bar" value={this.state.bar}/>
|
||||
</Formsy.Form>
|
||||
);
|
||||
}
|
||||
});
|
||||
var form = TestUtils.renderIntoDocument(<TestForm/>);
|
||||
|
||||
form.setState({
|
||||
foo: {foo: 'foo'},
|
||||
bar: ['bar']
|
||||
});
|
||||
|
||||
var inputs = TestUtils.scryRenderedComponentsWithType(form, TestInput);
|
||||
expect(inputs[0].getValue()).toEqual({foo: 'foo'});
|
||||
expect(inputs[1].getValue()).toEqual(['bar']);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
var utils = require('./utils.js');
|
||||
|
||||
var convertValidationsToObject = function (validations) {
|
||||
|
||||
if (typeof validations === 'string') {
|
||||
|
|
@ -77,11 +79,10 @@ module.exports = {
|
|||
|
||||
var isValueChanged = function () {
|
||||
|
||||
return this.props.value !== prevProps.value && this.state._value === prevProps.value;
|
||||
return !utils.isSame(this.props.value, prevProps.value) && utils.isSame(this.state._value, prevProps.value);
|
||||
|
||||
}.bind(this);
|
||||
|
||||
|
||||
// If validations has changed or something outside changes
|
||||
// the value, set the value again running a validation
|
||||
if (isValueChanged()) {
|
||||
|
|
|
|||
37
src/utils.js
37
src/utils.js
|
|
@ -1,15 +1,42 @@
|
|||
module.exports = {
|
||||
arraysDiffer: function (arrayA, arrayB) {
|
||||
arraysDiffer: function (a, b) {
|
||||
var isDifferent = false;
|
||||
if (arrayA.length !== arrayB.length) {
|
||||
if (a.length !== b.length) {
|
||||
isDifferent = true;
|
||||
} else {
|
||||
arrayA.forEach(function (item, index) {
|
||||
if (item !== arrayB[index]) {
|
||||
a.forEach(function (item, index) {
|
||||
if (!this.isSame(item, b[index])) {
|
||||
isDifferent = true;
|
||||
}
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
return isDifferent;
|
||||
},
|
||||
objectsDiffer: function (a, b) {
|
||||
var isDifferent = false;
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
isDifferent = true;
|
||||
} else {
|
||||
Object.keys(a).forEach(function (key) {
|
||||
if (!this.isSame(a[key], b[key])) {
|
||||
isDifferent = true;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
return isDifferent;
|
||||
},
|
||||
isSame: function (a, b) {
|
||||
|
||||
if (a !== b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Array.isArray(a)) {
|
||||
return !this.arraysDiffer(a, b);
|
||||
} else if (typeof a === 'object' && a !== null) {
|
||||
return !this.objectsDiffer(a, b);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ module.exports = {
|
|||
|
||||
module: {
|
||||
loaders: [
|
||||
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' }
|
||||
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' },
|
||||
{ test: /\.json$/, loader: 'json' }
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
var path = require('path');
|
||||
|
||||
module.exports = {
|
||||
|
||||
devtool: 'source-map',
|
||||
entry: path.resolve(__dirname, 'src', 'main.js'),
|
||||
externals: 'react',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'release'),
|
||||
filename: 'formsy-react.js',
|
||||
libraryTarget: 'umd',
|
||||
library: 'Formsy'
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' },
|
||||
{ test: /\.json$/, loader: 'json' }
|
||||
]
|
||||
}
|
||||
|
||||
};
|
||||
Loading…
Reference in New Issue