Fix EntityPicker allowing clear value when required #16993

Signed-off-by: Martin Morales <morales-martin@outlook.com>
This commit is contained in:
Martin Morales
2023-03-23 18:47:05 -05:00
parent b268dab386
commit b71f58d7d8
2 changed files with 7 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder': minor
---
Fixed bug in EntityPicker component that allowed for empty values when field is required. This bug occurs only after a user fills the EntityPicker field, clears it, and then continues to the next form step.
@@ -96,7 +96,8 @@ export const EntityPicker = (props: EntityPickerProps) => {
(_: any, ref: string | Entity | null, reason: AutocompleteChangeReason) => {
// ref can either be a string from free solo entry or
if (typeof ref !== 'string') {
onChange(ref ? stringifyEntityRef(ref as Entity) : '');
// if ref does not exist: pass 'undefined' to trigger validation for non-free solo entries
onChange(ref ? stringifyEntityRef(ref as Entity) : undefined);
} else {
if (reason === 'blur' || reason === 'create-option') {
// Add in default namespace, etc.