
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
form-validate-angular
Advanced tools
## Description When you give this ``Directive`` to a form element that is ill with ``NgForm``, it checks the validation rules of automatically linked elements and makes the class of those that fail the check ``is-invalid``. At the same time, if there is a
When you give this Directive
to a form element that is ill with NgForm
, it checks the validation rules of automatically linked elements and makes the class of those that fail the check is-invalid
. At the same time, if there is a div that gives a warning message, it automatically writes the validation error in it by default, if you want, you can write customized errors yourself.
import { FormValidateDirective } from 'form-validate-angular';
Component({
imports: [CommonModule, FormsModule, FormValidateDirective],
})
import { FormValidateDirective } from 'form-validate-angular';
@NgModule({
imports: [
CommonModule,
FormsModule,
FormValidateDirective
]
})
export class AppModule { }
<form formValidate #form="ngForm" autocomplete="off">
<form formValidate [customValidateMessage]="false" #form="ngForm" autocomplete="off">
<form formValidate #form="ngForm" autocomplete="off">
<div class="form-group">
Email
<input class="form-control" name="email" ngModel required email type="email">
</div>
<div class="form-group">
Content
<textarea class="form-control" name="content" ngModel required minlength="5" cols="30" rows="10"></textarea>
<div class="invalid-feedback">Örnek Uyarı</div>
</div>
<button class="btn btn-primary">Send</button>
</form>
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
@Directive({
selector: '[formValidate]',
standalone: true
})
export class FormValidateDirective {
@Input("customValidateMessage") customValidateMessage: boolean = true;
constructor(
private el: ElementRef<HTMLFormElement>
) { }
@HostListener("keyup") keyup(){
this.checkValidation();
}
@HostListener("submit") submit(){
this.checkValidation();
}
checkValidation(){
for(let child in this.el.nativeElement.elements){
const childElement:any = this.el.nativeElement.elements[child]
if(childElement.validity !== undefined){
const elName:any = "[name=" + childElement.name + "] + div";
let divEl : any;
if(childElement.name !== ""){
divEl = document.querySelector(elName);
}
if(!childElement.validity.valid){
if(this.customValidateMessage && divEl !== null)
divEl.innerHTML = childElement.validationMessage;
childElement.classList.add("is-invalid");
childElement.classList.remove("is-valid");
}else{
childElement.classList.add("is-valid");
childElement.classList.remove("is-invalid");
}
}
}
}
}
Thanks to Serap for helping me with this library idea. :)
FAQs
When you give this ``Directive`` to a form element that is ill with ``NgForm``, it checks the validation rules of automatically linked elements and makes the class of those that fail the check ``is-invalid``. At the same time, if there is a div that gives
The npm package form-validate-angular receives a total of 12 weekly downloads. As such, form-validate-angular popularity was classified as not popular.
We found that form-validate-angular demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.