diff --git a/apps/demo/src/pages/pizza-delivery.astro b/apps/demo/src/pages/pizza-delivery.astro index d12ed0e..af48a83 100644 --- a/apps/demo/src/pages/pizza-delivery.astro +++ b/apps/demo/src/pages/pizza-delivery.astro @@ -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)]); --- diff --git a/package-lock.json b/package-lock.json index dd4601b..b79ef8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/packages/form/core/form-control.ts b/packages/form/core/form-control.ts index 58839ca..07d80c2 100644 --- a/packages/form/core/form-control.ts +++ b/packages/form/core/form-control.ts @@ -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() {