Skip to content

Commit

Permalink
moved some relevant.js customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnR committed Apr 17, 2024
1 parent 11c73bf commit 85c173a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 51 deletions.
17 changes: 15 additions & 2 deletions packages/enketo-core/src/js/relevant.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ export default {
update(updated, forceClearNonRelevant = config.forceClearNonRelevant) {
const nodes = this.form
.getRelatedNodes('data-relevant', '', updated)
// the OC customization: **always** add
// .or-group.invalid-relevant and .or-group-data.invalid-relevant
.add(
this.form.getRelatedNodes('data-relevant', '.invalid-relevant')
)
.get();

// OC sets forceClearNonRelevant to false always
forceClearNonRelevant = false;
this.updateNodes(nodes, forceClearNonRelevant, updated ?? {});
},

Expand Down Expand Up @@ -331,8 +337,12 @@ export default {
selfRelevant(branchNode) {
return (
!branchNode.classList.contains('disabled') &&
!branchNode.classList.contains('pre-init')
!branchNode.classList.contains('pre-init') &&
!branchNode.classList.contains('invalid-relevant')
);
// The third clause is an OC customization that ensures
// that a branch will not be disabled if it has a question with
//a value.

Check failure on line 345 in packages/enketo-core/src/js/relevant.js

View workflow job for this annotation

GitHub Actions / lint (20.5.1)

Expected exception block, space or tab after '//' in comment

Check failure on line 345 in packages/enketo-core/src/js/relevant.js

View workflow job for this annotation

GitHub Actions / lint (20.5.1)

Expected exception block, space or tab after '//' in comment
},

/**
Expand Down Expand Up @@ -526,6 +536,9 @@ export default {
this.form.widgets.enable(branchNode);
this.activate(branchNode);
}
// OC customization to remove any shown irrelevant errors on the group
// (and perhaps question as well?) once it becomes relevant again.
branchNode.classList.remove('invalid-relevant');

return change;
},
Expand Down
49 changes: 0 additions & 49 deletions packages/enketo-express/public/js/src/module/relevant.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,6 @@ import branchModule from 'enketo-core/src/js/relevant';
import { getXPath } from 'enketo-core/src/js/dom-utils';
import events from 'enketo-core/src/js/event';

/**
* Overwrite core functionality by **always** adding
* .or-group.invalid-relevant and .or-group-data.invalid-relevant.
*
* @param updated
*/
branchModule.update = function (updated) {
if (!this.form) {
throw new Error(
'Branch module not correctly instantiated with form property.'
);
}

const nodes = this.form
.getRelatedNodes('data-relevant', '', updated)
// the OC customization:
.add(this.form.getRelatedNodes('data-relevant', '.invalid-relevant'))
.get();

this.updateNodes(nodes);
};

branchModule.originalSelfRelevant = branchModule.selfRelevant;

// Overwrite in order to add the && !branchNode.classList.contains('invalid-relevant') clause because an irrelevant branch in OC,
// would not be disabled if it is a question with a value!
branchModule.selfRelevant = function (branchNode) {
return (
this.originalSelfRelevant(branchNode) &&
!branchNode.classList.contains('invalid-relevant')
);
};

branchModule.originalEnable = branchModule.enable;

/**
* Overwrite core functionality.
* The reason for this customization is to remove any shown irrelevant errors on the group (and perhaps question as well?)
* once it becomes relevant again.
*
* @param branchNode
* @param path
*/
branchModule.enable = function (branchNode, path) {
const change = this.originalEnable(branchNode, path);
branchNode.classList.remove('invalid-relevant');

return change;
};

Check failure on line 7 in packages/enketo-express/public/js/src/module/relevant.js

View workflow job for this annotation

GitHub Actions / lint (20.5.1)

Delete `⏎`

Check failure on line 7 in packages/enketo-express/public/js/src/module/relevant.js

View workflow job for this annotation

GitHub Actions / lint (20.5.1)

Delete `⏎`
/*
* Overwrite to always call this.clear if ever enabled and currently relevant.
Expand Down

0 comments on commit 85c173a

Please sign in to comment.