factorial-form
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -222,2 +222,12 @@ import { Field } from '../src' | ||
}) | ||
describe('reset', () => { | ||
it('resets a field to its original value', () => { | ||
const field = new Field('paco', 'string') | ||
field.set('ferran') | ||
expect(field.value).toBe('ferran') | ||
field.reset() | ||
expect(field.value).toBe('paco') | ||
}) | ||
}) | ||
}) |
@@ -158,2 +158,13 @@ import { Form } from '../src' | ||
describe('resetAll', () => { | ||
it('resets form to its original values', () => { | ||
form.setValues({ name: 'resetMe', age: 20 }) | ||
expect(form.get('name').value).toBe('resetMe') | ||
expect(form.get('age').value).toBe("20") | ||
form.resetAll() | ||
expect(form.get('name').value).toBe('paco') | ||
expect(form.get('age').value).toBe("0") | ||
}) | ||
}) | ||
describe('setErrors', () => { | ||
@@ -160,0 +171,0 @@ it('populates the fields with errors', () => { |
# Changelog | ||
## `2.1.0` | ||
- Add `reset` and `resetAll` methods | ||
## `2.0.0` | ||
@@ -4,0 +8,0 @@ |
@@ -22,2 +22,3 @@ declare type Type = 'date' | 'timestamp' | 'number' | 'string' | 'file' | 'boolean' | 'cents' | 'any'; | ||
clean(): void; | ||
reset(): void; | ||
setErrors(errors: Array<string> | null): void; | ||
@@ -59,7 +60,12 @@ } | ||
/** | ||
* Cleans all the forms by reseting their original | ||
* values | ||
* Cleans all the forms by changing their original | ||
* values to correspond to their current values | ||
*/ | ||
cleanAll(): void; | ||
/** | ||
* Reset all the forms to their original | ||
* values thereby discarding all changes made | ||
*/ | ||
resetAll(): void; | ||
/** | ||
* Resets all the error fields | ||
@@ -66,0 +72,0 @@ */ |
@@ -199,2 +199,5 @@ 'use strict'; | ||
}; | ||
Field.prototype.reset = function () { | ||
this.value = this.originalValue; | ||
}; | ||
Field.prototype.setErrors = function (errors) { | ||
@@ -241,4 +244,4 @@ this.errors = errors; | ||
/** | ||
* Cleans all the forms by reseting their original | ||
* values | ||
* Cleans all the forms by changing their original | ||
* values to correspond to their current values | ||
*/ | ||
@@ -251,2 +254,11 @@ Form.prototype.cleanAll = function () { | ||
/** | ||
* Reset all the forms to their original | ||
* values thereby discarding all changes made | ||
*/ | ||
Form.prototype.resetAll = function () { | ||
forEach__default['default'](this.fields, function (field) { | ||
return field.reset(); | ||
}); | ||
}; | ||
/** | ||
* Resets all the error fields | ||
@@ -253,0 +265,0 @@ */ |
{ | ||
"name": "factorial-form", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Factorial form library", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146187
26
1504
1