mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-24 08:01:07 +02:00
* moves validators from model-helpers to forms directory * creates validate util and updates model-validations directory to use it * adds form and field classes * updates validation types * updates validators import in test * adds readme for forms * Update ui/app/utils/forms/validate.ts Co-authored-by: lane-wetmore <lane.wetmore@hashicorp.com> --------- Co-authored-by: lane-wetmore <lane.wetmore@hashicorp.com>
28 lines
752 B
JavaScript
28 lines
752 B
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { validate } from 'vault/utils/forms/validate';
|
|
|
|
// see documentation at ui/docs/model-validations.md for detailed usage information
|
|
export function withModelValidations(validations) {
|
|
return function decorator(SuperClass) {
|
|
return class ModelValidations extends SuperClass {
|
|
static _validations;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
if (!validations || typeof validations !== 'object') {
|
|
throw new Error('Validations object must be provided to constructor for setup');
|
|
}
|
|
this._validations = validations;
|
|
}
|
|
|
|
validate() {
|
|
return validate(this, this._validations);
|
|
}
|
|
};
|
|
};
|
|
}
|