Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fixed: broken multiple-constraint feature (probably broken for a long…
Browse files Browse the repository at this point in the history
… time)
  • Loading branch information
MartijnR committed Jul 21, 2023
1 parent d6269d3 commit 2af567c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
11 changes: 3 additions & 8 deletions public/js/src/module/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ Form.constraintNames = Array.from(Array(21)).map(
(val, i) => `constraint${i !== 0 ? i : ''}`
);

Form.extendedBy = 'what';
Form.prototype.extendedBy = 'OpenClinica';

Object.defineProperty(Form, 'extendedBy', {
value: 'OpenClinica',
writable: false
});

Object.defineProperty(Form, 'constraintClassesInvalid', {
Object.defineProperty(Form.prototype, 'constraintClassesInvalid', {
get: () => Form.constraintNames.map((n) => `invalid-${n}`),
});

Object.defineProperty(Form, 'constraintAttributes', {
Object.defineProperty(Form.prototype, 'constraintAttributes', {
get: () =>
Form.constraintNames.map((n, i) => `data-${i === 0 ? n : `oc-${n}`}`),
});
Expand Down
6 changes: 3 additions & 3 deletions public/js/src/module/input.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Modify the Enketo Core input module.

import inputModule from 'enketo-core/src/js/input';
/* eslint import/no-cycle: "off" */
import { Form } from './form';

// Obtain multiple constraints
inputModule.getConstraint = function (control) {
// The array index corresponds to the number used in oc:constraint
// Note if a spot is missing, e.g. constraint11, this will (deliberately) result in an undefined value,

return Form.constraintAttributes.map((attr) => control.getAttribute(attr));
return this.form.constraintAttributes.map((attr) =>
control.getAttribute(attr)
);
};
2 changes: 0 additions & 2 deletions test/client/form-extensions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@ describe('Extended Form Class', () => {
expect(form.constraintClassesInvalid.length).to.be.above(1);
});
});


0 comments on commit 2af567c

Please sign in to comment.