Skip to content

Commit

Permalink
Merged in r2-3005-required_fields (pull request #6933)
Browse files Browse the repository at this point in the history
R2-3005: Fixing issue where multiselects with display conditions and a undefined value skips vailidation on edit

Approved-by: Dennis Hernandez
  • Loading branch information
jtoliver-quoin committed Sep 20, 2024
2 parents 3a002f7 + 4e844c2 commit 375cc8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/javascript/components/record-form/form/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const fieldValidations = (field, { i18n, online = false }) => {
},
then: $schema => {
if (type === SELECT_FIELD && multiSelect) {
return $schema.min(1, requiredMessage);
return $schema.min(1, requiredMessage).default([]);
}

if (type === TALLY_FIELD) {
Expand Down Expand Up @@ -193,7 +193,7 @@ export const fieldValidations = (field, { i18n, online = false }) => {
}

if (type === SELECT_FIELD && multiSelect) {
validations[name] = schema.min(1, requiredMessage).required(requiredMessage);
validations[name] = schema.min(1, requiredMessage).required(requiredMessage).default([]);
}

if (type === TALLY_FIELD) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@ describe("<RecordForm>/form/validations", () => {
required: true
};

it("should not be valid if it is empty", () => {
it("should not be valid if it is empty array", () => {
const schema = object().shape(validations.fieldValidations({ ...selectField, required: true }, { i18n }));
const formData = { cities: [] };

expect(schema.isValidSync(formData)).to.be.false;
});

it("should not be valid if it is null", () => {
it("should not be valid if it is null or undefined", () => {
const schema = object().shape(validations.fieldValidations({ ...selectField, required: true }, { i18n }));
const formData = { cities: null };

expect(schema.isValidSync(formData)).to.be.false;
expect(schema.isValidSync({ cities: null })).to.be.false;
expect(schema.isValidSync({ cities: undefined })).to.be.false;
expect(schema.isValidSync({})).to.be.false;
});

it("should not be valid if it is not present", () => {
Expand Down Expand Up @@ -168,7 +169,7 @@ describe("<RecordForm>/form/validations", () => {
);
const formData = { testField: 1 };

expect(schema.isValidSync(formData)).to.be.true;
expect(schema.isValidSync(formData)).to.be.false;
});
});
});
Expand Down

0 comments on commit 375cc8c

Please sign in to comment.