OValidatorComponent

Using the o-validator component allows to define a validator function that will be applied to its parent input. It also allows to define a single error message.

Example

   <o-text-input attr="input" label="{{ 'INPUT.BUTTON.TEXT' | oTranslate }}">
        <o-validator error-name="requiredB" error-text="Must contain a 'b'" 
          [validator-function]="bValidator">
        </o-validator>
  </o-text-input>
  ...

  import { ValidationErrors, FormControl } from '@angular/forms';

  bValidator(control: FormControl): ValidationErrors {
    if (control.value && control.value.toString().indexOf('b') === -1) {
      return {
        'requiredB': true
      };
    }
    return {};
  }

  ...

If the new validator has more than one possible error result, user must use the o-error component to define the multiple errors messages.

Directive: o-validator

Inputs

Name Description Default

error-name

string

Name of the configured error

error-text

string

Message displayed when the configured error is present in the component

validator-function

ValidatorFn

Custom validators to apply to the component value. It must be a Angular ValidatorFn

[]

Updated: