Skip to content

Commit

Permalink
Fixed possible NPE in FormField testId generation
Browse files Browse the repository at this point in the history
CR with Anselm
  • Loading branch information
jskupsik committed Jan 18, 2024
1 parent 76105ed commit 3128b31
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions desktop/cmp/form/FormField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const [FormField, formField] = hoistCmp.withFactory<FormFieldProps>({
if (disabled) classes.push('xh-form-field-disabled');
if (displayNotValid) classes.push('xh-form-field-invalid');

const testId = getFormFieldTestId(props, formContext, model.name);
const testId = getFormFieldTestId(props, formContext, model?.name);
useOnMount(() => instanceManager.registerModelWithTestId(testId, model));
useOnUnmount(() => instanceManager.unregisterModelWithTestId(testId));

Expand Down Expand Up @@ -369,5 +369,8 @@ function getFormFieldTestId(
formContext: FormContextType,
fieldName: string
): string {
return props.testId ?? (formContext.testId ? `${formContext.testId}-${fieldName}` : undefined);
return (
props.testId ??
(formContext.testId && fieldName ? `${formContext.testId}-${fieldName}` : undefined)
);
}

0 comments on commit 3128b31

Please sign in to comment.