NG Absolute Form Validator - V14.1

RequiredIf

The Required If rule makes a field mandatory only when another named field on the same form equals a specific value — required_if:requiredIf_1,a means the current field must be present and non-empty whenever requiredIf_1 holds the value a. It's the check behind conditional form sections, like requiring a 'company name' field only when an account-type field is set to business, or requiring a 'reason for return' field only when a return-type dropdown is set to defective. The field being watched needs to be defined or initialized before the field that depends on it, so its current value is already available at the point this rule runs.

#Directive Code Snippet
<!DOCTYPE html> 
<html lang="en"> 
    ...
    <form (ngSubmit)="onSubmit(form)" #form="ngForm">
		<input [requiredIf]="[<TARGET_FIELD>,<MATCH_VALUE>]" type="text" name="<name>" [(ngModel)]="<name>" #<name>="ngModel">
        <ng-absolute-validator [formInstance]="<name>"></ng-absolute-validator>
	</form>
    ...
</html>
#Chain Rule Code Snippet
<!DOCTYPE html> 
<html lang="en"> 
    ...
    <form (ngSubmit)="onSubmit(form)" #form="ngForm">
		<input rule="required_if:<TARGET_FIELD>,<MATCH_VALUE>" type="text" name="<name>" [(ngModel)]="<name>" #<name>="ngModel">
        <ng-absolute-validator [formInstance]="<name>"></ng-absolute-validator>
	</form>
    ...
</html>
#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.map('required_if:<TARGET_FIELD>,<MATCH_VALUE>',<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>)"></ng-absolute-validator>
	</form>
    ...
</html>