From 9b2d9598e8258c17e245b9763093f65c29261d45 Mon Sep 17 00:00:00 2001 From: christianalfoni Date: Sat, 25 Apr 2015 12:20:39 +0200 Subject: [PATCH] added pull request and created tests and documentation --- API.md | 4 ++-- specs/Formsy-spec.jsx | 19 +++++++++++++++++++ src/main.js | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index d1e338d..f64cf56 100644 --- a/API.md +++ b/API.md @@ -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. -#### resetForm() +#### reset() ```html var MyForm = React.createClass({ resetForm: function () { diff --git a/specs/Formsy-spec.jsx b/specs/Formsy-spec.jsx index 95b9c6e..b483a7f 100755 --- a/specs/Formsy-spec.jsx +++ b/specs/Formsy-spec.jsx @@ -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(); + 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(); + 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); + }); }); }); diff --git a/src/main.js b/src/main.js index f6208b7..93caeac 100644 --- a/src/main.js +++ b/src/main.js @@ -74,7 +74,7 @@ Formsy.Form = React.createClass({ }.bind(this), 0); }, - resetForm: function () { + reset: function () { this.setFormPristine(true); this.resetModel(); },