ValidatorOptional

oneOf

Accept only values from a list.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';

@Component({ imports: [WrInput] })
export class MyComponent {}

Live demo

Try xs, sm, md, lg or xl. Anything else fails.

errors: null

Usage

import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';

const size = new FormControl('', [
  WrValidators.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
]);

API

NameDescriptionTypeDefault
signatureCall it with the allowed values.<T>(allowed: readonly T[]) => ValidatorFn—
comparisonStrict ===.——
error keyOn failure: { oneOf: { allowed: [...] } }. Empty value passes.{ oneOf: { allowed } }—

See also