Exists
The Exists rule performs remote validation, sending the field's value to a backend endpoint to confirm it's actually present in your database — for example, checking that a referral code, a username, or a domain is a real, known record before letting the form proceed. Both GET and POST are supported for the request, with GET used by default. Because it depends on an HTTP round trip to your own API rather than a synchronous, self-contained check, it's asynchronous by nature and isn't available through the pipe-delimited chain-rule syntax — it needs the Template Driven or Reactive binding modes, where an async validator can be wired in properly.
#Directive Code Snippet
<!DOCTYPE html>
<html lang="en">
...
<form (ngSubmit)="onSubmit(form)" #form="ngForm">
<input [exists]="{url:<API_URL>,method:<method>}" type="text" name="<name>" [(ngModel)]="<name>" #<name>="ngModel">
<ng-absolute-validator [formInstance]="<name1>" [loader]="true"></ng-absolute-validator>
</form>
...
</html>
#Chain Rule Code Snippet
Exists Validation does not support yet.
#Reactive Form Code Snippet
//component.ts
export class ReactiveComponent{
public form !: FormGroup;
constructor(
private fb : FormBuilder,
private rv : ReactiveValidator,
){this.generteForm()}
generteForm(){
this.form = this.fb.group({
<name> : ['',[],[this.rv.exists({url:'http://jsonplaceholder.typicode.com/users'},<CUSTOM_MESSAGE>)]],
})
}
}
//component.html
<!DOCTYPE html>
<html lang="en">
...
<form [formGroup]="form">
<input type="text" name="<name>" formControlName="<name>">
<ng-absolute-validator [formInstance]="form.get(<name>)" [loader]="true"></ng-absolute-validator>
</form>
...
</html>
#Config Options:
| Property | Type | Required | Description |
|---|---|---|---|
url |
string |
Yes | The endpoint URL to which the HTTP request will be sent. |
field |
string |
No | The specific field/property name to be used or mapped from the response. by default it will be the form name |
request |
object |
No | The request body/payload to be sent with the HTTP call. Typically used with POST requests. |
params |
object |
No | Query parameters to be appended to the URL (used with GET requests or additional filters). |
method |
'GET' | 'POST' |
No | The HTTP method to use for the request. Defaults to 'GET' if not specified. |