Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
26b113b
Make validation controlled and async
oandregal Aug 29, 2025
9b1fa80
Remove isItemValid
oandregal Oct 15, 2025
1acbc8f
Document useIsFormValid hook
oandregal Oct 15, 2025
c965fa8
Test useIsFormValid: port all existing test for isItemValid
oandregal Oct 15, 2025
219dd24
Update FieldValidity and FormValidity types
oandregal Oct 15, 2025
3cbe36d
useIsFormValid: update tests
oandregal Oct 15, 2025
744e219
Update docs
oandregal Oct 15, 2025
81579ac
Create getCustomValidity utility
oandregal Oct 15, 2025
9ff587b
Update tests
oandregal Oct 15, 2025
16676bb
Rename useIsFormValid to useFormValidity
oandregal Oct 15, 2025
522dd49
useFormValidity returns validity and isValid
oandregal Oct 15, 2025
b2600d0
Add a test for isValid
oandregal Oct 15, 2025
af2bc15
DataForm: datetime control uses validity prop
oandregal Oct 15, 2025
2121abb
DataForm: date control uses validity prop
oandregal Oct 15, 2025
e067e62
Add changelog
oandregal Oct 15, 2025
f8d2252
DataForm: date control attaches different class depending on type
oandregal Oct 15, 2025
1851f70
Fix unmounting issue with panel dropdown/modal
oandregal Oct 16, 2025
10862ef
getCustomValidity: fall through to elements or custom if validity.req…
oandregal Oct 16, 2025
e80ff81
Update changelog
oandregal Oct 16, 2025
84b0a5d
Update README
oandregal Oct 16, 2025
224089f
Story: better custom Edit
oandregal Oct 16, 2025
b1979b1
Support combined fields.
oandregal Oct 16, 2025
1027148
Make linter happy
oandregal Oct 16, 2025
375c4a8
story: remove unnecessary flags
oandregal Oct 16, 2025
22c8cb7
Move useFormValidity test to proper place
oandregal Oct 16, 2025
12f88bf
Improve useFormValidity hook
oandregal Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make linter happy
  • Loading branch information
oandregal committed Oct 16, 2025
commit 10271482e3f43087ba5861d54f4342cc8074be73
40 changes: 28 additions & 12 deletions packages/dataviews/src/hooks/use-form-validity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ function isFormValid( formValidity: FormValidity | undefined ): boolean {
}

return Object.values( formValidity ).every( ( fieldValidation ) => {
return Object.entries( fieldValidation ).every( ( [ key, validation ] ) => {
if ( key === 'children' && validation && typeof validation === 'object' ) {
// Recursively check children validations
return isFormValid( validation as FormValidity );
return Object.entries( fieldValidation ).every(
( [ key, validation ] ) => {
if (
key === 'children' &&
validation &&
typeof validation === 'object'
) {
// Recursively check children validations
return isFormValid( validation as FormValidity );
}
return validation.type === 'valid';
}
return validation.type === 'valid';
} );
);
} );
}

Expand All @@ -82,7 +88,9 @@ function updateFieldValidity(
children: {
...prev?.[ parentFieldId ]?.children,
[ fieldId ]: {
...( prev?.[ parentFieldId ]?.children as any )?.[ fieldId ],
...( prev?.[ parentFieldId ]?.children as any )?.[
fieldId
],
...validationUpdate,
},
},
Expand Down Expand Up @@ -136,7 +144,8 @@ export function useFormValidity< Item >(
const combinedField = formField as CombinedFormField;
if ( combinedField.children ) {
combinedField.children.forEach( ( child ) => {
const childId = typeof child === 'string' ? child : child.id;
const childId =
typeof child === 'string' ? child : child.id;
fieldIdsToValidate.add( childId );
fieldParentMap.set( childId, combinedField.id );
} );
Expand Down Expand Up @@ -197,7 +206,8 @@ export function useFormValidity< Item >(
{
elements: {
type: 'invalid',
message: 'Value must be one of the elements.',
message:
'Value must be one of the elements.',
},
},
parentFieldId
Expand Down Expand Up @@ -357,15 +367,21 @@ export function useFormValidity< Item >(
return prev;
}

const { [ field.id ]: removed, ...restChildren } = parentField.children as any;
const { [ field.id ]: removed, ...restChildren } =
parentField.children as any;

// If no more children, remove the children property
if ( Object.keys( restChildren ).length === 0 ) {
const { children, ...restParent } = parentField;
if ( Object.keys( restParent ).length === 0 ) {
// Remove parent field entirely if no other validations
const { [ parentFieldId ]: removedParent, ...restFields } = prev;
return Object.keys( restFields ).length === 0 ? undefined : restFields;
const {
[ parentFieldId ]: removedParent,
...restFields
} = prev;
return Object.keys( restFields ).length === 0
? undefined
: restFields;
}
return {
...prev,
Expand Down