Skip to content

Commit c3e87e2

Browse files
committed
fix[release]: resolve date field change handler TypeError and multiple change events
- Fix TypeError when changing date field types by properly handling parent element traversal - Prevent multiple change events by separating UI logic from change tracking - Update storePendingChange to merge duplicate changes instead of creating new ones - Skip change handling for new properties added during editing sessions - Simplify date-type-selector parent element lookup logic
1 parent 5ca7cb1 commit c3e87e2

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

heritrace/static/js/creation_workflow.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,29 @@ function initializeForm() {
278278
}
279279

280280
function storePendingChange(action, subject, predicate, object, newObject = null, shape = null, entity_type = null, entity_shape = null) {
281+
// For 'update' actions, check if there's already a pending change for the same subject/predicate/object/shape
282+
if (action === 'update') {
283+
let existingChangeIndex = pendingChanges.findIndex(change =>
284+
change.action === 'update' &&
285+
change.subject === subject &&
286+
change.predicate === predicate &&
287+
change.object === object &&
288+
change.shape === shape
289+
);
290+
291+
if (existingChangeIndex !== -1) {
292+
// Update the existing change with the new value
293+
pendingChanges[existingChangeIndex].newObject = newObject;
294+
return;
295+
}
296+
}
297+
298+
// If no existing change found, add a new one
281299
pendingChanges.push({
282-
action: action,
283-
subject: subject,
284-
predicate: predicate,
285-
object: object,
300+
action: action,
301+
subject: subject,
302+
predicate: predicate,
303+
object: object,
286304
newObject: newObject,
287305
shape: shape,
288306
entity_type: entity_type,
@@ -757,8 +775,9 @@ $(document).ready(function() {
757775
if (originalValue) {
758776
let newType = $(this).val();
759777
let newValue = convertDate(originalValue, newType);
778+
// Just set the value without triggering change events
760779
dateInputGroup.find(`.date-input[data-date-type="${newType}"]`).val(newValue);
761-
dateInputGroup.find('.date-display').text(newValue);
780+
dateInputGroup.find('.date-display').text(newValue);
762781
}
763782

764783
showAppropriateDateInput($(this));

heritrace/templates/entity/about.jinja

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,11 @@
722722
});
723723
724724
$(document).on('change', '.editable-field[id^="new_value_"], .editable-select, .date-type-selector', function() {
725+
// Skip change handling for new properties added during editing
726+
if ($(this).closest('.added-in-edit-mode').length > 0) {
727+
return;
728+
}
729+
725730
const listItem = $(this).closest('.property-value');
726731
const subject = listItem.data('subject-id');
727732
const predicate = listItem.data('property-id');

0 commit comments

Comments
 (0)