added pull request and created tests and documentation

This commit is contained in:
christianalfoni 2015-04-25 12:20:39 +02:00
parent accc0815db
commit 9b2d9598e8
3 changed files with 22 additions and 3 deletions

4
API.md
View File

@ -11,7 +11,7 @@
- [onValidSubmit()](#onvalidsubmit)
- [onInvalidSubmit()](#oninvalidsubmit)
- [onChange()](#onchange)
- [resetForm()](#resetform)
- [reset()](#resetform)
- [Formsy.Mixin](#formsymixin)
- [name](#name)
- [value](#value)
@ -142,7 +142,7 @@ 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>
#### <a name="resetform">reset()</a>
```html
var MyForm = React.createClass({
resetForm: function () {

View File

@ -593,5 +593,24 @@ describe('Formsy', function () {
TestUtils.Simulate.submit(form.getDOMNode());
expect(onSubmit).toHaveBeenCalledWith({foo: false});
});
it("should say the form is submitted", function() {
var form = TestUtils.renderIntoDocument(<TestForm value={ true }/>);
var input = TestUtils.findRenderedComponentWithType(form, TestInput);
expect(input.isFormSubmitted()).toBe(false);
TestUtils.Simulate.submit(form.getDOMNode());
expect(input.isFormSubmitted()).toBe(true);
});
it("should be able to reset the form to its pristine state", function() {
var form = TestUtils.renderIntoDocument(<TestForm value={ true }/>);
var input = TestUtils.findRenderedComponentWithType(form, TestInput);
var formsyForm = TestUtils.findRenderedComponentWithType(form, Formsy.Form);
expect(input.getValue()).toBe(true);
form.setProps({value: false});
expect(input.getValue()).toBe(false);
formsyForm.reset();
expect(input.getValue()).toBe(true);
});
});
});

View File

@ -74,7 +74,7 @@ Formsy.Form = React.createClass({
}.bind(this), 0);
},
resetForm: function () {
reset: function () {
this.setFormPristine(true);
this.resetModel();
},