Comparing version 0.4.1 to 0.5.0
@@ -57,3 +57,7 @@ import { Validation, ValidationError, Validator } from "./validation"; | ||
addValidators<U extends T = T>(...validators: Validator<T, U>[]): Field<Either<U, T>>; | ||
/** | ||
* Sets the field to an invalid state with the specified error. | ||
*/ | ||
setError(error: unknown): this; | ||
} | ||
export {}; |
@@ -78,2 +78,9 @@ "use strict"; | ||
} | ||
/** | ||
* Sets the field to an invalid state with the specified error. | ||
*/ | ||
setError(error) { | ||
this.validation = (0, validation_1.createFailedValidation)([error]); | ||
return this; | ||
} | ||
} | ||
@@ -93,1 +100,4 @@ exports.Field = Field; | ||
], Field.prototype, "validate", null); | ||
__decorate([ | ||
mobx_1.action | ||
], Field.prototype, "setError", null); |
@@ -74,2 +74,6 @@ type PendingValidation = { | ||
export declare function createValidation<InvalidValue, Value extends InvalidValue = InvalidValue>(...validators: (Validator<InvalidValue, Value> | Validator<InvalidValue, Value>[])[]): Validation<InvalidValue, Value>; | ||
/** | ||
* Create a validation state in the invalid state, using the given errors. | ||
*/ | ||
export declare function createFailedValidation(errors?: readonly unknown[]): Validation<any>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createValidation = exports.AGGREGATE_ERROR = exports.ValidationError = void 0; | ||
exports.createFailedValidation = exports.createValidation = exports.AGGREGATE_ERROR = exports.ValidationError = void 0; | ||
const mobx_1 = require("mobx"); | ||
@@ -89,1 +89,16 @@ class ValidationError extends Error { | ||
exports.createValidation = createValidation; | ||
/** | ||
* Create a validation state in the invalid state, using the given errors. | ||
*/ | ||
function createFailedValidation(errors = []) { | ||
return { | ||
state: "invalid", | ||
value: undefined, | ||
errors: errors.map((error) => ValidationError.from(error)), | ||
get hasError() { | ||
return this.errors.length > 0; | ||
}, | ||
async validate() { }, | ||
}; | ||
} | ||
exports.createFailedValidation = createFailedValidation; |
@@ -5,3 +5,3 @@ { | ||
"repository": "gustavohenke/fielded", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "homepage": "https://gustavohenke.github.io/fielded/", |
# fielded | ||
[![CI Status](https://img.shields.io/github/actions/workflow/status/gustavohenke/fielded/ci.yml?style=flat-square)](https://github.com/gustavohenke/fielded/actions/workflows/ci.yml) | ||
[![NPM Version](https://img.shields.io/npm/v/fielded?style=flat-square)](https://www.npmjs.com/package/fielded) | ||
fielded is a library for managing form state on the web or Node.js. | ||
Please refer to the documentation website for more information: https://gustavohenke.github.io/fielded/ |
Sorry, the diff of this file is not supported yet
44409
19
781
10