Skip to content

Commit b2508d9

Browse files
committed
Add SHACL form patch to preserve multi-value blank nodes
1 parent 64eb3e0 commit b2508d9

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

previewers/betatest/CdiPreview.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
77
<script type="text/javascript" src="js/xss.js"></script>
88
<script type="module" src="js/shacl-form.js"></script>
9+
<script type="text/javascript" src="js/shacl-form-patch.js"></script>
910
<script src="lib/jquery.i18n.js"></script>
1011
<script src="lib/jquery.i18n.messagestore.js"></script>
1112
<script src="lib/jquery.i18n.language.js"></script>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Guard the shacl-form implementation so that multi-value blank nodes remain visible even when
3+
* nested nodes currently violate their shape (e.g., missing required fields). Without this guard
4+
* the component drops every value after validation and users cannot fix the data.
5+
*
6+
* This patch must be loaded AFTER the shacl-form web component is imported.
7+
*/
8+
9+
(function() {
10+
'use strict';
11+
12+
// Wait for custom elements to be defined
13+
async function applyPatch() {
14+
// Wait for shacl-property element to be defined
15+
await customElements.whenDefined('shacl-property');
16+
17+
const shaclPropertyCtor = customElements.get('shacl-property');
18+
19+
if (shaclPropertyCtor && !shaclPropertyCtor.__rdmFilterGuardApplied) {
20+
const prototype = shaclPropertyCtor.prototype;
21+
const originalFilter = prototype.filterValidValues;
22+
23+
if (typeof originalFilter === 'function') {
24+
console.log('[SHACL Patch] Applying filterValidValues guard for multi-value blank nodes');
25+
26+
prototype.filterValidValues = async function(values, subject) {
27+
// If there's no qualifiedValueShape, don't filter - keep all values
28+
if (!this?.template?.qualifiedValueShape) {
29+
return values;
30+
}
31+
32+
// Otherwise, use the original validation logic
33+
return originalFilter.call(this, values, subject);
34+
};
35+
36+
shaclPropertyCtor.__rdmFilterGuardApplied = true;
37+
console.log('[SHACL Patch] Guard applied successfully');
38+
} else {
39+
console.warn('[SHACL Patch] filterValidValues method not found');
40+
}
41+
} else if (shaclPropertyCtor?.__rdmFilterGuardApplied) {
42+
console.log('[SHACL Patch] Guard already applied');
43+
} else {
44+
console.error('[SHACL Patch] shacl-property element not found');
45+
}
46+
}
47+
48+
// Apply patch when DOM is ready
49+
if (document.readyState === 'loading') {
50+
document.addEventListener('DOMContentLoaded', applyPatch);
51+
} else {
52+
applyPatch();
53+
}
54+
})();

0 commit comments

Comments
 (0)