Closed CynthiaKamau closed 3 months ago
Size Change: +2.52 kB (+0.25%)
Total Size: 1.01 MB
@CynthiaKamau I pushed a commit to simplify the logic, can you kindly test out the latest changes?
@CynthiaKamau I pushed a commit to simplify the logic, can you kindly test out the latest changes?
A heads up on the ticket would have been nice to avoid duplicated efforts
The PR title reads like it also addresses a similar problem for the "select" inputs but I don't see any related logic, is this a draft? Did we reach a consensus on how to approach this?
If not, here is a rough one:
The idea is adding an extra option (at index 0) which represents empty or "no-op". The tricky part is the wording for the label. I've seen many forms with real options labeled as "None", "N/A" etc. To solve this problem, we can drive this through a config:
{
"id": "example-question",
"label": "Example Question",
"questionOptions": {
"rendering": "select",
"answers": [
{ "label": "Option 1", "value": "1" },
{ "label": "Option 2", "value": "2" }
],
"emptyOptionLabel": "None",
}
}
We then add this option conditionally based on whether emptyOptionLabel
exists:
(src/transformers/default-schema-transformer.ts)
function setFirstDropdownOptionToNoop(question: FormField) {
const label = question.questionOptions['emptyOptionLabel'];
if (Array.isArray(question.questionOptions.answers) && label) {
const firstOption = question.questionOptions.answers[0];
if (firstOption?.value !== '') {
question.questionOptions.answers.unshift({ label, value: 'NOOP' });
}
}
}
// ... existing code ...
function transformByRendering(question: FormField) {
switch (question.questionOptions.rendering as any) {
// ... existing code ...
case 'select':
setFirstDropdownOptionToNoop(question);
break;
// ... existing code ...
}
return question;
}
We then adjust the input:
<DropdownInput
id={question.id}
// other props
onChange={({ selectedItem }) => handleChange(selectedItem === 'NOOP' ? null : selectedItem)}
/>
Thoughts?? @brandones @arodidev @denniskigen
Requirements
Summary
When an answer is selected on a radio button field the is no way the user can clear is selection. This pr attempts to address that.
Screenshots
https://github.com/openmrs/openmrs-form-engine-lib/assets/19533785/96d0646f-2d35-4d3f-ae84-f103a4f20f51
Related Issue
Other