Skip to content

Commit

Permalink
(fix)Fixes jumping cursor issue (#147)
Browse files Browse the repository at this point in the history
* Fixes jumping cursor issue

* Update src/api/types.ts

* Update src/components/encounter/ohri-encounter-form.component.tsx

---------

Co-authored-by: Pius Rubangakene <[email protected]>
  • Loading branch information
arodidev and pirupius authored Nov 21, 2023
1 parent 5255df8 commit 9d330dc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export interface OHRIFormFieldProps {
value: any,
setErrors: (errors: Array<ValidationResult>) => void,
setWarnings: (warnings: Array<ValidationResult>) => void,
isUnspecified?: boolean,
) => void;
handler: SubmissionHandler;
// This is of util to components defined out of the engine
Expand Down
19 changes: 11 additions & 8 deletions src/components/encounter/ohri-encounter-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
value: any,
setErrors: (errors: Array<ValidationResult>) => void,
setWarnings: (warnings: Array<ValidationResult>) => void,
isUnspecified: boolean,
) => {
const field = fields.find((field) => field.id == fieldName);
const validators = Array.isArray(field.validators)
Expand All @@ -533,14 +534,16 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
};
const errors = [];
const warnings = [];
for (let validatorConfig of validators) {
const errorsAndWarinings =
formFieldValidators[validatorConfig.type].validate(field, value, {
...basevalidatorConfig,
...validatorConfig,
}) || [];
errors.push(...errorsAndWarinings.filter((error) => error.resultType == 'error'));
warnings.push(...errorsAndWarinings.filter((error) => error.resultType == 'warning'));
if (!isUnspecified) {
for (let validatorConfig of validators) {
const errorsAndWarinings =
formFieldValidators[validatorConfig.type].validate(field, value, {
...basevalidatorConfig,
...validatorConfig,
}) || [];
errors.push(...errorsAndWarinings.filter((error) => error.resultType == 'error'));
warnings.push(...errorsAndWarinings.filter((error) => error.resultType == 'warning'));
}
}
setErrors?.(errors);
setWarnings?.(warnings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const OHRIUnspecified: React.FC<OHRIFormFieldProps> = ({ question, onChan
const handleOnChange = useCallback(
(value) => {
setFieldValue(`${question.id}-unspecified`, value.target.checked);
onChange(question.id, field.value, setErrors, setWarnings);
onChange(question.id, field.value, setErrors, setWarnings, value.target.checked);
question.value = handler?.handleFieldSubmission(question, field.value, encounterContext);
},
[fields],
Expand Down

0 comments on commit 9d330dc

Please sign in to comment.