Skip to content

Commit

Permalink
chore: update server validation (#4994)
Browse files Browse the repository at this point in the history
remove server validation for required fields
  • Loading branch information
timarney authored Jan 17, 2025
1 parent 334007b commit 09a2fd6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
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

0 comments on commit 09a2fd6

Please sign in to comment.