mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 02:24:36 -04:00
* added npm package to resolve typescript dependencies * OO JS forms * OO forms * Refactors forms to abstract form CRUD * Working on Promises * Fix for errors in js form * Form validation with array of data * Client update validation - array * handle array validation * Toastr notifications * Clean up
74 lines
1.1 KiB
TypeScript
74 lines
1.1 KiB
TypeScript
export default class FormErrors {
|
|
|
|
errors:any;
|
|
/**
|
|
* Create a new Errors instance.
|
|
*/
|
|
constructor() {
|
|
this.errors = {};
|
|
}
|
|
|
|
|
|
/**
|
|
* Determine if an errors exists for the given field.
|
|
*
|
|
* @param {string} field
|
|
*/
|
|
has(field:string) {
|
|
return this.errors.hasOwnProperty(field);
|
|
}
|
|
|
|
|
|
/**
|
|
* Determine if we have any errors.
|
|
*/
|
|
any() {
|
|
return Object.keys(this.errors).length > 0;
|
|
}
|
|
|
|
|
|
/**
|
|
* Retrieve the error message for a field.
|
|
*
|
|
* @param {string} field
|
|
*/
|
|
get(field:string) {
|
|
if (this.errors[field]) {
|
|
return this.errors[field][0];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Record the new errors.
|
|
*
|
|
* @param {object} errors
|
|
*/
|
|
record(errors:any) {
|
|
this.errors = errors;
|
|
}
|
|
|
|
|
|
/**
|
|
* Clear one or all error fields.
|
|
*
|
|
* @param {string|null} field
|
|
*/
|
|
clear(field:string) {
|
|
if (field) {
|
|
delete this.errors[field];
|
|
|
|
return;
|
|
}
|
|
|
|
this.errors = {};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//@keydown="errors.clear($event.target.name)"
|
|
//
|
|
//
|
|
//
|