feat(form): add method setValidators to FormControl (#170)
This commit is contained in:
parent
f502e6ca24
commit
c38e5dfbe3
3 changed files with 12 additions and 1 deletions
|
@ -88,6 +88,7 @@ const infoForm = new FormGroup([
|
||||||
baseForm.name = "Base";
|
baseForm.name = "Base";
|
||||||
toppingsForm.name = "Toppings";
|
toppingsForm.name = "Toppings";
|
||||||
infoForm.name = "Customer Info";
|
infoForm.name = "Customer Info";
|
||||||
|
infoForm.get("contact")?.setValidators([Validators.minLength(9)]);
|
||||||
---
|
---
|
||||||
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -9039,7 +9039,11 @@
|
||||||
},
|
},
|
||||||
"packages/form": {
|
"packages/form": {
|
||||||
"name": "@astro-reactive/form",
|
"name": "@astro-reactive/form",
|
||||||
|
<<<<<<< HEAD
|
||||||
|
"version": "0.5.1",
|
||||||
|
=======
|
||||||
"version": "0.5.4",
|
"version": "0.5.4",
|
||||||
|
>>>>>>> 640e9459599e09751fc539f3db92bab9cd47ab89
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astro-reactive/common": "^0.0.3",
|
"@astro-reactive/common": "^0.0.3",
|
||||||
|
|
|
@ -118,7 +118,13 @@ export class FormControl {
|
||||||
setValue(value: string) {
|
setValue(value: string) {
|
||||||
this._value = value;
|
this._value = value;
|
||||||
this._isPristine = false;
|
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() {
|
clearErrors() {
|
||||||
|
|
Loading…
Reference in a new issue