MCPcopy
hub / github.com/angular/angular / required

Function required

packages/forms/signals/src/api/rules/validation/required.ts:33–53  ·  view source on GitHub ↗
(
  path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>,
  config?: BaseValidatorConfig<TValue, TPathKind> & {
    when?: NoInfer<LogicFn<TValue, boolean, TPathKind>>;
  },
)

Source from the content-addressed store, hash-verified

31 * @publicApi 22.0
32 */
33export function required<TValue, TPathKind extends PathKind = PathKind.Root>(
34 path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>,
35 config?: BaseValidatorConfig<TValue, TPathKind> & {
36 when?: NoInfer<LogicFn<TValue, boolean, TPathKind>>;
37 },
38): void {
39 const REQUIRED_MEMO = metadata(path, createMetadataKey<boolean>(), (ctx) =>
40 config?.when ? config.when(ctx) : true,
41 );
42 metadata(path, REQUIRED, ({state}) => state.metadata(REQUIRED_MEMO)!()!);
43 validate(path, (ctx) => {
44 if (ctx.state.metadata(REQUIRED_MEMO)!() && isEmpty(ctx.value())) {
45 if (config?.error) {
46 return getOption(config.error, ctx);
47 } else {
48 return requiredError({message: getOption(config?.message, ctx)});
49 }
50 }
51 return undefined;
52 });
53}

Callers 15

TestCmpClass · 0.90
webmcp.spec.tsFile · 0.90
structure.spec.tsFile · 0.90
LoginComponentClass · 0.90
AppClass · 0.90
AppClass · 0.90
AppClass · 0.90
AppClass · 0.90
AppClass · 0.90
AppClass · 0.90

Calls 9

metadataFunction · 0.90
createMetadataKeyFunction · 0.90
validateFunction · 0.90
isEmptyFunction · 0.90
getOptionFunction · 0.90
requiredErrorFunction · 0.90
whenMethod · 0.80
metadataMethod · 0.65
valueMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…