Skip to content

Commit

Permalink
refactor: Clear old error message on session object when updating val…
Browse files Browse the repository at this point in the history
…id submission data and pass previous value into React component tckt-363

Co-authored-by: Daniel Naab [email protected]
  • Loading branch information
kalasgarov committed Nov 13, 2024
1 parent 31f98d3 commit a89b9df
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 6 additions & 4 deletions packages/forms/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
type FormErrorType = 'required' | 'custom';

export type FormError = {
type: FormErrorType;
message?: string;
};
export type FormError =
| {
type?: FormErrorType;
message?: string;
}
| undefined;

export type FormErrors = Record<string, FormError>;
1 change: 1 addition & 0 deletions packages/forms/src/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const validatePatternAndChildren = (

if (parseResult.success) {
result.values[pattern.id] = parseResult.data;
result.errors[pattern.id] = undefined;
} else {
result.values[pattern.id] = values[pattern.id];
result.errors[pattern.id] = parseResult.error;
Expand Down
6 changes: 4 additions & 2 deletions packages/forms/src/patterns/page-set/submit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ describe('Page-set submission', () => {
session: {
...session,
data: {
errors: {},
errors: {
'input-1': undefined,
},
values: {
'input-1': 'test',
},
},
route: {
url: '#',
params: {
page: '1',
page: '0',
},
},
form: session.form,
Expand Down
7 changes: 5 additions & 2 deletions packages/forms/src/services/submit-form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,17 @@ describe('multi-page form', () => {
session: {
...session,
data: {
errors: {},
attachments: undefined,
errors: {
'element-1': undefined,
},
values: {
'element-1': 'test',
},
},
route: {
params: {
page: '1',
page: '0',
},
url: '#',
},
Expand Down

0 comments on commit a89b9df

Please sign in to comment.