Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support validate intent to validate a full fieldset (all fields with a given prefix) #830

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions packages/conform-dom/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ function handleIntent<Error>(
switch (intent.type) {
case 'validate': {
if (intent.payload.name) {
if (intent.payload.recursive) {
const allNames = Object.keys(meta.error).concat(fields ?? []);
for (const name of allNames) {
if (isPrefix(name, intent.payload.name)) {
meta.validated[name] = true;
}
}
}
meta.validated[intent.payload.name] = true;
} else {
setFieldsValidated(meta, fields);
Expand Down
1 change: 1 addition & 0 deletions packages/conform-dom/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export type ValidateIntent<Schema = any> = {
type: 'validate';
payload: {
name?: FieldName<Schema>;
recursive?: boolean;
};
};

Expand Down
Loading