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

chore: update server validation #4994

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function submitForm(
throw new Error(`Could not find any form associated to identifier ${formId}`);
}

const validateResponsesResult = await validateResponses(values, template, language);
const validateResponsesResult = await validateResponses(values, template);

if (Object.keys(validateResponsesResult).length !== 0) {
logMessage.warn(
Expand Down
25 changes: 1 addition & 24 deletions lib/validation/validation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { inGroup } from "@lib/formContext";
import { isFileExtensionValid, isAllFilesSizeValid } from "./fileValidationClientSide";
import { DateObject } from "@clientComponents/forms/FormattedDate/types";
import { isValidDate } from "@clientComponents/forms/FormattedDate/utils";
import { serverTranslation } from "@i18n";

/**
* getRegexByType [private] defines a mapping between the types of fields that need to be validated
Expand Down Expand Up @@ -286,14 +285,8 @@ const valueMatchesType = (value: unknown, type: string, formElement: FormElement
/**
* Server-side validation the form responses
*/
export const validateResponses = async (
values: Responses,
formRecord: PublicFormRecord,
language: string
) => {
export const validateResponses = async (values: Responses, formRecord: PublicFormRecord) => {
const errors: Responses = {};
const { t } = await serverTranslation(["common"], { lang: language });

for (const item in values) {
const formElement = formRecord.form.elements.find((element) => element.id == parseInt(item));

Expand All @@ -308,22 +301,6 @@ export const validateResponses = async (
if (!result) {
errors[item] = "invalid-response-data-type";
}

// Check for required fields
if (formElement.properties.validation) {
const result = isFieldResponseValid(
values[item],
values,
formElement.type,
formElement,
formElement.properties.validation,
t
);

if (result) {
errors[item] = result;
}
}
}

return errors;
Expand Down
Loading