Skip to content

Commit 16e29e6

Browse files
committed
fix(frontend): keep custom field values across create-modal type changes
Reloading the create screen after a workspace or item type change reset every custom field value to its default, silently discarding values the user had already entered for fields that remain configured on the new screen. Submitting then persisted the empty default, so values picked before a type switch (e.g. an asset Component) were lost. Preserve entered values for fields still configured after the reload; only fields new to the screen get their default. Applies to the desktop store and the mobile create dialog.
1 parent 475d094 commit 16e29e6

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

frontend/src/lib/mobile/MobileCreateDialog.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,19 @@
334334
const customIds = fields
335335
.filter((field) => field.field_type === 'custom')
336336
.map((field) => parseInt(field.field_identifier, 10));
337+
// Preserve entered values for fields that remain configured across the
338+
// workspace/type change; only fields new to the screen get defaults.
339+
const previousValues = customFieldValues;
337340
customFieldValues = {};
338341
for (const field of allCustomFields) {
339342
if (customIds.includes(field.id)) {
340-
customFieldValues[field.id] = isBooleanCustomFieldType(field.field_type) ? false : '';
343+
const previous = previousValues[field.id];
344+
customFieldValues[field.id] =
345+
previous !== undefined && previous !== null && previous !== ''
346+
? previous
347+
: isBooleanCustomFieldType(field.field_type)
348+
? false
349+
: '';
341350
}
342351
}
343352
screenFieldsLoadedForKey = key;

frontend/src/lib/stores/workItemFormStore.svelte.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,20 @@ class WorkItemFormStore {
542542
customFieldIds.includes(field.id)
543543
);
544544

545-
// Reset custom field values for new fields
545+
// Keep values the user already entered for fields that remain configured
546+
// across the workspace/type change; only fields new to the screen get
547+
// their default. Resetting wholesale silently discarded picks when the
548+
// item type changed after a field was filled.
549+
const previousValues = this.customFieldValues;
546550
this.customFieldValues = {};
547551
filteredCustomFields.forEach((field) => {
548-
this.customFieldValues[field.id] = isBooleanCustomFieldType(field.field_type) ? false : '';
552+
const previous = previousValues[field.id];
553+
this.customFieldValues[field.id] =
554+
previous !== undefined && previous !== null && previous !== ''
555+
? previous
556+
: isBooleanCustomFieldType(field.field_type)
557+
? false
558+
: '';
549559
});
550560

551561
this.customFields = filteredCustomFields;

0 commit comments

Comments
 (0)