Skip to content

Commit 4b0e759

Browse files
committed
better comment on validateMember
1 parent 6e30acb commit 4b0e759

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

app/forms/subnet-pool-member-add.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,23 @@ const defaultValues: MemberAddForm = {
4343

4444
type ValidationErrors = Partial<Record<keyof MemberAddForm, string>>
4545

46-
export function validateMember(poolVersion: IpVersion, values: MemberAddForm) {
46+
/**
47+
* This function is a sneaky way to back into cross-field validation while only
48+
* hooking into the field-level `validate` callback. This function looks at all
49+
* the form `values` together and sets errors for each field in the form, and
50+
* then the callsites look like this: they all call it the same way and just
51+
* pluck their own error off the result.
52+
*
53+
* ```ts
54+
* validate={(_maxPrefixLength, values) =>
55+
* validateMember(poolData.ipVersion, values).maxPrefixLength
56+
* }
57+
* ```
58+
*/
59+
export function validateMember(
60+
poolVersion: IpVersion,
61+
values: MemberAddForm
62+
): ValidationErrors {
4763
const maxBound = poolVersion === 'v4' ? 32 : 128
4864
const parsed = parseIpNet(values.subnet)
4965
const { minPrefixLength: minPL, maxPrefixLength: maxPL } = values

0 commit comments

Comments
 (0)