MCPcopy Create free account
hub / github.com/angular/angular / required

Function required

packages/forms/signals/src/api/rules/validation/required.ts:43–63  ·  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

41 * @publicApi 22.0
42 */
43export function required<TValue, TPathKind extends PathKind = PathKind.Root>(
44 path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>,
45 config?: BaseValidatorConfig<TValue, TPathKind> & {
46 when?: NoInfer<LogicFn<TValue, boolean, TPathKind>>;
47 },
48): void {
49 const REQUIRED_MEMO = metadata(path, createMetadataKey<boolean>(), (ctx) =>
50 config?.when ? config.when(ctx) : true,
51 );
52 metadata(path, REQUIRED, ({state}) => state.metadata(REQUIRED_MEMO)!()!);
53 validate(path, (ctx) => {
54 if (ctx.state.metadata(REQUIRED_MEMO)!() && isEmpty(ctx.value())) {
55 if (config?.error) {
56 return getOption(config.error, ctx);
57 } else {
58 return requiredError({message: getOption(config?.message, ctx)});
59 }
60 }
61 return undefined;
62 });
63}

Callers 15

TestCmpClass · 0.90
webmcp.spec.tsFile · 0.90
structure.spec.tsFile · 0.90
debounce.spec.tsFile · 0.90
AppClass · 0.90
LoginComponentClass · 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