Comparing version 0.6.3 to 0.7.0
@@ -39,9 +39,34 @@ import { Field } from "./field"; | ||
/** | ||
* Observable, first validation error of the form. | ||
* Observable, first validation error from the form's nested fields, or if there aren't any, | ||
* its own validation errors. | ||
* | ||
* This works like this because the form validators expect all fields to be valid before running. | ||
* @see addValidators | ||
*/ | ||
get error(): ValidationError | undefined; | ||
/** | ||
* Observable list of validation errors of the form. | ||
* Observable list of validation errors either from the form's nested fields, | ||
* or if there aren't any, the form's own validation errors. | ||
* | ||
* This works like this because the form validators expect all fields to be valid before running. | ||
* @see addValidators | ||
*/ | ||
get errors(): readonly ValidationError[]; | ||
/** | ||
* Observable, first validation error from the form itself. | ||
*/ | ||
get formError(): ValidationError | undefined; | ||
/** | ||
* Observable list of validation errors from the form itself. | ||
*/ | ||
get formErrors(): readonly ValidationError[]; | ||
/** | ||
* Observable, first validation error from any of the form's nested fields. | ||
*/ | ||
get fieldError(): ValidationError | undefined; | ||
/** | ||
* Observable list of validation errors from its nested fields, | ||
* followed by the form's own validation errors. | ||
*/ | ||
get fieldErrors(): readonly ValidationError[]; | ||
constructor(fields: T); | ||
@@ -48,0 +73,0 @@ /** |
@@ -24,3 +24,7 @@ "use strict"; | ||
/** | ||
* Observable, first validation error of the form. | ||
* Observable, first validation error from the form's nested fields, or if there aren't any, | ||
* its own validation errors. | ||
* | ||
* This works like this because the form validators expect all fields to be valid before running. | ||
* @see addValidators | ||
*/ | ||
@@ -31,7 +35,39 @@ get error() { | ||
/** | ||
* Observable list of validation errors of the form. | ||
* Observable list of validation errors either from the form's nested fields, | ||
* or if there aren't any, the form's own validation errors. | ||
* | ||
* This works like this because the form validators expect all fields to be valid before running. | ||
* @see addValidators | ||
*/ | ||
get errors() { | ||
if (this.fieldErrors.length) { | ||
return this.fieldErrors; | ||
} | ||
return this.formErrors; | ||
} | ||
/** | ||
* Observable, first validation error from the form itself. | ||
*/ | ||
get formError() { | ||
return this.formErrors.at(0); | ||
} | ||
/** | ||
* Observable list of validation errors from the form itself. | ||
*/ | ||
get formErrors() { | ||
return this.validation?.errors || []; | ||
} | ||
/** | ||
* Observable, first validation error from any of the form's nested fields. | ||
*/ | ||
get fieldError() { | ||
return this.fieldErrors.at(0); | ||
} | ||
/** | ||
* Observable list of validation errors from its nested fields, | ||
* followed by the form's own validation errors. | ||
*/ | ||
get fieldErrors() { | ||
return Object.values(this.fields).flatMap((field) => field.errors); | ||
} | ||
constructor(fields) { | ||
@@ -98,2 +134,8 @@ this.fields = fields; | ||
__decorate([ | ||
mobx_1.computed | ||
], Form.prototype, "errors", null); | ||
__decorate([ | ||
mobx_1.computed | ||
], Form.prototype, "fieldErrors", null); | ||
__decorate([ | ||
mobx_1.action | ||
@@ -100,0 +142,0 @@ ], Form.prototype, "reset", null); |
@@ -59,5 +59,3 @@ "use strict"; | ||
try { | ||
result = await (typeof validator === "function" | ||
? validator(value) | ||
: validator.validate(value)); | ||
await (typeof validator === "function" ? validator(value) : validator.validate(value)); | ||
} | ||
@@ -67,3 +65,3 @@ catch (e) { | ||
result = e; | ||
return; | ||
break; | ||
} | ||
@@ -70,0 +68,0 @@ const error = ValidationError.from(e); |
@@ -5,3 +5,3 @@ { | ||
"repository": "gustavohenke/fielded", | ||
"version": "0.6.3", | ||
"version": "0.7.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "homepage": "https://gustavohenke.github.io/fielded/", |
Sorry, the diff of this file is not supported yet
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
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
51754
932