Skip to main content
Version: 0.10.0

uniqueExcept

Like unique, but ignores one record — for edit forms where the value legitimately belongs to the record being edited. The exceptId is sent alongside the value (param except).

Signature

NguardValidators.Async.uniqueExcept(exceptId: primitive, config: AsyncValidatorConfig): AsyncValidatorFn
ParameterTypeDescription
exceptIdprimitiveThe id of the record to exclude from the uniqueness check
configAsyncValidatorConfigSame config as unique, including the resolve callback

Default rule (no resolve)

Same as unique: 2xx → taken (invalid { unique: true }), 404 → free (valid), anything else → undecided (valid).

Reactive forms

import { FormControl } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';

email = new FormControl('', {
asyncValidators: [NguardValidators.Async.uniqueExcept(this.user.id, { endpoint: '/api/users/check-email' })],
});

Template-driven forms

<input
ngModel
name="email"
[nguardUniqueExcept]="{ endpoint: '/api/users/check-email' }"
[nguardUniqueExceptId]="user.id"
/>

Error key

{ unique: true }

Notes

  • Reports the same unique error key as unique.
  • Sends except={exceptId} (query param for GET, body key for POST/PUT) so the backend skips that record.
  • Must be created in an injection context; debounced with cancellation. Override the status-code default with config.resolve when needed.

See also

  • unique — create forms (no record to exclude)