Skip to content
Merged
Show file tree
Hide file tree
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
Rename useIsFormValid to useFormValidity
  • Loading branch information
oandregal committed Oct 16, 2025
commit 16676bb0f3af2f6d20ebf31bf5018d3eb49ffae6
2 changes: 1 addition & 1 deletion packages/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ Returns an object containing:
- `totalItems`: total number of items for the current view config.
- `totalPages`: total number of pages for the current view config.

### `useIsFormValid`
### `useFormValidity`

Hook to determine if a form is valid.

Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Internal dependencies
*/
export { default as useIsFormValid } from './use-is-form-valid';
export { default as useFormValidity } from './use-form-validity';
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { renderHook } from '@testing-library/react';
/**
* Internal dependencies
*/
import { useIsFormValid } from '../';
import { useFormValidity } from '..';
import type { Field } from '../../types';

describe( 'useIsFormValid', () => {
describe( 'useFormValidity', () => {
it( 'operates on form fields and ignores the rest', () => {
const item = { id: 1, valid_order: 2, invalid_order: 'd' };
const fields: Field< {} >[] = [
Expand All @@ -24,7 +24,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'valid_order' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -47,7 +47,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'order' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -69,7 +69,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'tags' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.tags ).toEqual( REQUIRED_MESSAGE );
} );
Expand All @@ -87,7 +87,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'tags' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.tags ).toEqual( REQUIRED_MESSAGE );
} );
Expand All @@ -105,7 +105,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'tags' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -131,7 +131,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'author' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.author ).toEqual( ELEMENTS_MESSAGE );
} );
Expand All @@ -153,7 +153,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'status' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -175,7 +175,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'status' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.status ).toEqual( ELEMENTS_MESSAGE );
} );
Expand All @@ -198,7 +198,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'priority' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -221,7 +221,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'priority' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.priority ).toEqual( ELEMENTS_MESSAGE );
} );
Expand All @@ -240,7 +240,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'price' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.price ).toEqual( ELEMENTS_MESSAGE );
} );
Expand All @@ -260,7 +260,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'tags' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -280,7 +280,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'tags' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.tags ).toEqual( ELEMENTS_MESSAGE );
} );
Expand All @@ -302,7 +302,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'tags' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.tags ).toEqual( ELEMENTS_MESSAGE );
} );
Expand All @@ -319,7 +319,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'order' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -334,7 +334,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'order' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.order ).toEqual( {
custom: {
Expand All @@ -354,7 +354,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'price' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current ).toEqual( undefined );
} );
Expand All @@ -369,7 +369,7 @@ describe( 'useIsFormValid', () => {
];
const form = { fields: [ 'price' ] };
const { result } = renderHook( () =>
useIsFormValid( item, fields, form )
useFormValidity( item, fields, form )
);
expect( result.current?.price ).toEqual( {
custom: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function isInvalidForRequired( fieldType: string | undefined, value: any ) {
*
* @return Record of field IDs to error messages (undefined means no error).
*/
export function useIsFormValid< Item >(
export function useFormValidity< Item >(
item: Item,
fields: Field< Item >[],
form: Form
Expand Down Expand Up @@ -290,4 +290,4 @@ export function useIsFormValid< Item >(
return formValidity;
}

export default useIsFormValid;
export default useFormValidity;
2 changes: 1 addition & 1 deletion packages/dataviews/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export { default as DataViews } from './components/dataviews';
export { default as DataViewsPicker } from './components/dataviews-picker';
export { default as DataForm } from './components/dataform';
export { default as filterSortAndPaginate } from './utils/filter-sort-and-paginate';
export { useIsFormValid } from './hooks';
export { useFormValidity } from './hooks';
export { VIEW_LAYOUTS } from './dataviews-layouts';
export type * from './types';
4 changes: 2 additions & 2 deletions packages/dataviews/src/stories/dataform.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
* Internal dependencies
*/
import DataForm from '../components/dataform';
import useIsFormValid from '../hooks/use-is-form-valid';
import useFormValidity from '../hooks/use-form-validity';

import type {
Field,
Expand Down Expand Up @@ -1012,7 +1012,7 @@ const ValidationComponent = ( {
],
};

const validity = useIsFormValid( post, _fields, form );
const validity = useFormValidity( post, _fields, form );

return (
<form>
Expand Down
4 changes: 2 additions & 2 deletions packages/fields/src/actions/reorder-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { store as coreStore } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { useState } from '@wordpress/element';
import { DataForm, useIsFormValid } from '@wordpress/dataviews';
import { DataForm, useFormValidity } from '@wordpress/dataviews';
import {
Button,
__experimentalHStack as HStack,
Expand Down Expand Up @@ -37,7 +37,7 @@ function ReorderModal( {
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

const validity = useIsFormValid( item, fields, formOrderAction );
const validity = useFormValidity( item, fields, formOrderAction );

async function onOrder( event: React.FormEvent ) {
event.preventDefault();
Expand Down