File

projects/ngx-persian/src/lib/Validators/persian-directives.ts

Description

You can add PersianLetterDirective property to your input tag for using persianNumbersValidator function on its value For setting options value, you can simply set PersianLetterDirective property equal to the PLOptions object. For more information also see persianLettersValidator

Implements

Validator

Metadata

Providers { provide: NG_VALIDATORS, useExisting: PersianLetterDirective }
Selector persianLettersValidator

Index

Methods
Inputs

Inputs

PersianLetterDirective
Type : PLOptions

Methods

validate
validate(control: AbstractControl)

Only a wrapper for persianLettersValidator validator function.

Parameters :
Name Type Optional
control AbstractControl No
Returns : literal type | null

null for success or ValidationError for invalid inputs

import {Directive, Input} from '@angular/core';
import {AbstractControl, NG_VALIDATORS, Validator} from '@angular/forms';
import {persianLettersValidator, persianNumbersValidator} from './persian-validators';
import {PLOptions} from '../Services/persian-letter.service';


/**
 * You can add PersianNumbersDirective property to your input tag for using persianNumbersValidator function on its value.
 *
 * [For more information also see persianNumbersValidator]{@link persianNumbersValidator}
 */
@Directive({
  selector: 'PersianNumbersDirective',
  providers: [{provide: NG_VALIDATORS, useExisting: PersianNumbersDirective}]
})
export class PersianNumbersDirective implements Validator {

  /**
   * Only a wrapper for persianNumbersValidator validator function.
   * @param control
   * @return null for success or ValidationError for invalid inputs
   */
  validate(control: AbstractControl): {[key: string]: any} | null {
    return persianNumbersValidator()(control);
  }
}

/**
 * You can add PersianLetterDirective property to your input tag for using persianNumbersValidator function on its value
 * For setting options value, you can simply set PersianLetterDirective property equal to the PLOptions object.
 * [For more information also see persianLettersValidator]{@link persianLettersValidator}
 */
@Directive({
  selector: 'persianLettersValidator',
  providers: [{provide: NG_VALIDATORS, useExisting: PersianLetterDirective}]
})
export class PersianLetterDirective implements Validator {

  @Input('PersianLetterDirective') options: PLOptions;

  /**
   * Only a wrapper for persianLettersValidator validator function.
   * @param control
   * @return null for success or ValidationError for invalid inputs
   */
  validate(control: AbstractControl): {[key: string]: any} | null {
    return persianLettersValidator(this.options)(control);
  }
}

result-matching ""

    No results matching ""