MCPcopy
hub / github.com/angular/angular / maxLength

Function maxLength

packages/forms/signals/src/api/rules/validation/max_length.ts:39–71  ·  view source on GitHub ↗
(
  path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>,
  maxLength: number | LogicFn<TValue, number | undefined, TPathKind>,
  config?: BaseValidatorConfig<TValue, TPathKind>,
)

Source from the content-addressed store, hash-verified

37 * @publicApi 22.0
38 */
39export function maxLength<
40 TValue extends ValueWithLengthOrSize,
41 TPathKind extends PathKind = PathKind.Root,
42>(
43 path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>,
44 maxLength: number | LogicFn<TValue, number | undefined, TPathKind>,
45 config?: BaseValidatorConfig<TValue, TPathKind>,
46) {
47 const MAX_LENGTH_MEMO = metadata(path, createMetadataKey<number | undefined>(), (ctx) => {
48 if (config?.when && !config.when(ctx)) {
49 return undefined;
50 }
51 return typeof maxLength === 'number' ? maxLength : maxLength(ctx);
52 });
53 metadata(path, MAX_LENGTH, ({state}) => state.metadata(MAX_LENGTH_MEMO)!());
54 validate(path, (ctx) => {
55 if (isEmpty(ctx.value())) {
56 return undefined;
57 }
58 const maxLength = ctx.state.metadata(MAX_LENGTH_MEMO)!();
59 if (maxLength === undefined) {
60 return undefined;
61 }
62 if (getLengthOrSize(ctx.value()) > maxLength) {
63 if (config?.error) {
64 return getOption(config.error, ctx);
65 } else {
66 return maxLengthError(maxLength, {message: getOption(config?.message, ctx)});
67 }
68 }
69 return undefined;
70 });
71}

Callers 3

TestCmpClass · 0.90
TestCmpClass · 0.85
max_length.spec.tsFile · 0.85

Calls 10

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…