Skip to content

Commit

Permalink
Disable non selectable options
Browse files Browse the repository at this point in the history
  • Loading branch information
holubv committed May 4, 2021
1 parent 6d778bf commit 8e1f4d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class Constants {
static HAS_UNIT_OF_MEASURE = 'http://onto.fel.cvut.cz/ontologies/form/has-unit-of-measure-question';
static HAS_TYPE_QUESTION = 'http://onto.fel.cvut.cz/ontologies/form/has-type-question';

static HAS_NON_SELECTABLE_VALUE = 'http://onto.fel.cvut.cz/ontologies/form/has-non-selectable-value';

static LAYOUT_TYPE_QUESTION = 'type-question';

static BROADER = 'http://www.w3.org/2004/02/skos/core#broader';
Expand Down
14 changes: 14 additions & 0 deletions src/components/TypeQuestionAnswer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ export default class TypeQuestionAnswer extends React.Component {
}
}

_checkNonSelectableOptions(tree) {
const question = this.props.question;

for (let o of Object.values(tree)) {
if (JsonLdUtils.hasValue(question, Constants.HAS_NON_SELECTABLE_VALUE, o.value)) {
o.disabled = true;
}
}
}

_checkDisjointOptions(tree, selected) {

for (let o of Object.values(tree)) {
Expand All @@ -180,6 +190,8 @@ export default class TypeQuestionAnswer extends React.Component {
this._checkMaxNumberOfAnswers(tree, selected);
}

this._checkNonSelectableOptions(tree);

return tree;
}

Expand Down Expand Up @@ -296,6 +308,8 @@ export default class TypeQuestionAnswer extends React.Component {
this._checkDisjointOptions(options, answers);
}

this._checkNonSelectableOptions(options);

console.log(options);

this.setState({
Expand Down
21 changes: 7 additions & 14 deletions test/form2.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
},
"has-type-question": {
"@id": "http://onto.fel.cvut.cz/ontologies/form/has-type-question"
},
"has-non-selectable-value": {
"@id": "http://onto.fel.cvut.cz/ontologies/form/has-non-selectable-value"
}
},
"@graph": [
Expand Down Expand Up @@ -254,8 +257,7 @@
"ps-type-1",
"ps-type-2",
"as-show-advanced-888",
"as-checkbox-452",
"provozovatel-no-section-888"
"as-checkbox-452"
],
"has-type-question": [
"ps-type-1",
Expand All @@ -273,6 +275,9 @@
"fyzicka-osoba--chytra",
"fyzicka-osoba--hloupa"
],
"has-non-selectable-value": [
"fyzicka-osoba"
],
"label": "Provozovatel"
},
{
Expand All @@ -293,18 +298,6 @@
"label": "show advanced",
"show-advanced-question": true
},
{
"@id": "provozovatel-no-section-888",
"@type": "doc:question",
"has_related_question": [],
"has-layout-class": "type-question",
"has-possible-value": [
"fyzicka-osoba--nezletila",
"fyzicka-osoba--chytra",
"fyzicka-osoba--hloupa"
],
"label": "Fyzická osoba"
},
{
"@id": "as-checkbox-452",
"@type": "doc:question",
Expand Down

0 comments on commit 8e1f4d4

Please sign in to comment.