-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
(fix) O3-3634: DatePicker input should clear when unspecified is checked #354
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,11 @@ import { type CalendarDate, getLocalTimeZone } from '@internationalized/date'; | |
const DateField: React.FC<FormFieldProps> = ({ question, onChange, handler, previousValue }) => { | ||
const { t } = useTranslation(); | ||
const [field] = useField(question.id); | ||
const [unspecifiedField] = useField(`${question.id}-unspecified`); | ||
const { setFieldValue, encounterContext, layoutType, workspaceLayout, fields } = React.useContext(FormContext); | ||
const [time, setTime] = useState(''); | ||
const { errors, setErrors, warnings, setWarnings } = useFieldValidationResults(question); | ||
const [key, setKey] = useState(0); | ||
|
||
const isInline = useMemo(() => { | ||
if (['view', 'embedded-view'].includes(encounterContext.sessionMode) || isTrue(question.readonly)) { | ||
|
@@ -82,7 +84,15 @@ const DateField: React.FC<FormFieldProps> = ({ question, onChange, handler, prev | |
} | ||
}, [field.value, time]); | ||
|
||
return encounterContext.sessionMode == 'view' || encounterContext.sessionMode == 'embedded-view' ? ( | ||
useEffect(() => { | ||
if (unspecifiedField.value) { | ||
setFieldValue(question.id, null); | ||
setTime(null); | ||
setKey(prevKey => prevKey + 1); | ||
} | ||
}, [unspecifiedField.value]); | ||
|
||
return encounterContext.sessionMode === 'view' || encounterContext.sessionMode === 'embedded-view' ? ( | ||
<FieldValueView | ||
label={t(question.label)} | ||
value={field.value instanceof Date ? getDisplay(field.value, question.datePickerFormat) : field.value} | ||
|
@@ -97,6 +107,7 @@ const DateField: React.FC<FormFieldProps> = ({ question, onChange, handler, prev | |
<div className={styles.datePickerSpacing}> | ||
<Layer> | ||
<OpenmrsDatePicker | ||
key={key} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use the field id as the key instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arodidev When using a dynamic key like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question id is not dynamic, and would be much more suited rather than the int here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The major issue is with how the OpenmrsDatePicker propagates the states from the main component to the DatePickerInput component in esm core, when the value is cleared it never trickles down cc @samuelmale There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ibacher any thoughts on the above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be fixed. |
||
id={question.id} | ||
onChange={onDateChange} | ||
labelText={ | ||
|
@@ -159,7 +170,7 @@ const DateField: React.FC<FormFieldProps> = ({ question, onChange, handler, prev | |
|
||
function getDisplay(date: Date, rendering: string) { | ||
const dateString = formatDate(date); | ||
if (rendering == 'both') { | ||
if (rendering === 'both') { | ||
return `${dateString} ${formatTime(date)}`; | ||
} | ||
return dateString; | ||
|
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.
Why do we use an int as key as increment it?
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.
CC @samuelmale