Fixed callbacks for onInvalidSubmit and onValidSubmit
This commit is contained in:
parent
e8cd6a8ce8
commit
d0af1375a2
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "formsy-react",
|
||||
"version": "0.12.1",
|
||||
"version": "0.12.2",
|
||||
"main": "src/main.js",
|
||||
"dependencies": {
|
||||
"react": "^0.13.1"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "formsy-react",
|
||||
"version": "0.12.1",
|
||||
"version": "0.12.2",
|
||||
"description": "A form input builder and validator for React JS",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ Formsy.Form = React.createClass({displayName: "Form",
|
|||
this.updateModel();
|
||||
var model = this.mapModel();
|
||||
this.props.onSubmit(model, this.resetModel, this.updateInputsWithError);
|
||||
this.state.isValid ? this.props.onValidSubmit(model, this.resetModel) : this.props.onInvalidSubmit(model, this.resetModel);
|
||||
this.state.isValid ? this.props.onValidSubmit(model, this.resetModel, this.updateInputsWithError) : this.props.onInvalidSubmit(model, this.resetModel, this.updateInputsWithError);
|
||||
|
||||
},
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -80,6 +80,68 @@ describe('Validation', function() {
|
|||
|
||||
});
|
||||
|
||||
it('should provide invalidate callback on onValiSubmit', function () {
|
||||
|
||||
var TestInput = React.createClass({
|
||||
mixins: [Formsy.Mixin],
|
||||
render: function () {
|
||||
return <input value={this.getValue()}/>
|
||||
}
|
||||
});
|
||||
var TestForm = React.createClass({
|
||||
invalidate: function (model, reset, invalidate) {
|
||||
invalidate({
|
||||
foo: 'bar'
|
||||
});
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<Formsy.Form onValidSubmit={this.invalidate}>
|
||||
<TestInput name="foo" value="foo"/>
|
||||
</Formsy.Form>
|
||||
);
|
||||
}
|
||||
});
|
||||
var form = TestUtils.renderIntoDocument(<TestForm/>);
|
||||
|
||||
var formEl = TestUtils.findRenderedDOMComponentWithTag(form, 'form');
|
||||
var input = TestUtils.findRenderedComponentWithType(form, TestInput);
|
||||
TestUtils.Simulate.submit(formEl);
|
||||
expect(input.isValid()).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
it('should provide invalidate callback on onInvalidSubmit', function () {
|
||||
|
||||
var TestInput = React.createClass({
|
||||
mixins: [Formsy.Mixin],
|
||||
render: function () {
|
||||
return <input value={this.getValue()}/>
|
||||
}
|
||||
});
|
||||
var TestForm = React.createClass({
|
||||
invalidate: function (model, reset, invalidate) {
|
||||
invalidate({
|
||||
foo: 'bar'
|
||||
});
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<Formsy.Form onInvalidSubmit={this.invalidate}>
|
||||
<TestInput name="foo" value="foo" validations="isEmail"/>
|
||||
</Formsy.Form>
|
||||
);
|
||||
}
|
||||
});
|
||||
var form = TestUtils.renderIntoDocument(<TestForm/>);
|
||||
|
||||
var formEl = TestUtils.findRenderedDOMComponentWithTag(form, 'form');
|
||||
var input = TestUtils.findRenderedComponentWithType(form, TestInput);
|
||||
TestUtils.Simulate.submit(formEl);
|
||||
expect(input.getErrorMessage()).toBe('bar');
|
||||
|
||||
});
|
||||
|
||||
it('RULE: isEmail', function () {
|
||||
|
||||
var isValid = jasmine.createSpy('valid');
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ Formsy.Form = React.createClass({
|
|||
this.updateModel();
|
||||
var model = this.mapModel();
|
||||
this.props.onSubmit(model, this.resetModel, this.updateInputsWithError);
|
||||
this.state.isValid ? this.props.onValidSubmit(model, this.resetModel) : this.props.onInvalidSubmit(model, this.resetModel);
|
||||
this.state.isValid ? this.props.onValidSubmit(model, this.resetModel, this.updateInputsWithError) : this.props.onInvalidSubmit(model, this.resetModel, this.updateInputsWithError);
|
||||
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue