feat(form): add method setValidators to FormControl (#170)

This commit is contained in:
Chase Reynolds 2022-10-31 14:27:06 -04:00 committed by GitHub
parent f502e6ca24
commit c38e5dfbe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -88,6 +88,7 @@ const infoForm = new FormGroup([
baseForm.name = "Base";
toppingsForm.name = "Toppings";
infoForm.name = "Customer Info";
infoForm.get("contact")?.setValidators([Validators.minLength(9)]);
---
<html lang="en">

4
package-lock.json generated
View file

@ -9039,7 +9039,11 @@
},
"packages/form": {
"name": "@astro-reactive/form",
<<<<<<< HEAD
"version": "0.5.1",
=======
"version": "0.5.4",
>>>>>>> 640e9459599e09751fc539f3db92bab9cd47ab89
"license": "MIT",
"dependencies": {
"@astro-reactive/common": "^0.0.3",

View file

@ -118,7 +118,13 @@ export class FormControl {
setValue(value: string) {
this._value = value;
this._isPristine = false;
this._errors = this.validate(this._value, this.config.validators || []);
this._errors = this.validate(value, this.config.validators || []);
}
setValidators(validators: string[]) {
this._validators = validators;
const valueStr: string = this._value?.toString() || '';
this._errors = this.validate(valueStr, this._validators || []);
}
clearErrors() {