-
Notifications
You must be signed in to change notification settings - Fork 59
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
(feat) O3-3061: Support for conditional answered validation #297
Conversation
65ef997
to
ecb2b4a
Compare
Opened this work for review purposes pending tests. |
if (field.meta?.submission) { | ||
setErrors((prevErrors) => [...prevErrors, ...(field.meta.submission.errors || [])]); | ||
setWarnings((prevWarnings) => [...prevWarnings, ...(field.meta.submission.warnings || [])]); | ||
if (field.meta?.submission?.errors) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meta object is initialised at a earlier stage so it's not necessary to optionally chain it.
src/utils/form-helper.ts
Outdated
@@ -37,6 +37,16 @@ export function isInlineView( | |||
return renderingType == 'single-line'; | |||
} | |||
|
|||
export function evaluateConditionalAnswered(field: FormField, flattenedFields: FormField[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allFields
reads better
const { referenceQuestionId, referenceQuestionAnswers, values, fields, message } = config; | ||
|
||
const referencedField = fields.find((field) => field.id === referenceQuestionId); | ||
const referencedFieldValue = values[referencedField.id] || referencedField.meta?.submission?.newValue?.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second part of the expressions presupposes the underlying field to be capturing an obs. I think referencing the values
object should suffice.
const referencedField = fields.find((field) => field.id === referenceQuestionId); | ||
const referencedFieldValue = values[referencedField.id] || referencedField.meta?.submission?.newValue?.value; | ||
|
||
if (!referencedFieldValue || !referenceQuestionAnswers.includes(referencedFieldValue)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we being doing something like:
if (!isEmpty(value) && !referenceQuestionAnswers.includes(referencedFieldValue)) {
return [{ resultType: 'error', errCode: 'invalid.valueSelected', message: message }];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @arodidev , left a comment
src/form-engine.test.tsx
Outdated
@@ -156,6 +157,52 @@ describe('Form engine component', () => { | |||
}); | |||
}); | |||
|
|||
describe('conditional answered validation', () => { | |||
it('should fail if target field has a value but no value is selected on the referenced field', () => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done @CynthiaKamau
Requirements
Summary
This PR aims to introduce conditional answered validation to the form's engine.
Screenshots
Screen.Recording.2024-05-30.at.19.59.17.mov
Related Issue
https://openmrs.atlassian.net/browse/O3-3061
Other