Skip to content

Commit

Permalink
Merge pull request #129 from indec-it/feat/hideOrDisableQuesitonsByDe…
Browse files Browse the repository at this point in the history
…fault

feat(utils): be able to hide or disable questions by default
  • Loading branch information
maximilianoforlenza authored Oct 1, 2024
2 parents f95f776 + 55d52c7 commit 0c35f98
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indec/form-builder",
"version": "3.5.9",
"version": "3.6.0",
"description": "Form builder",
"main": "index.js",
"private": false,
Expand Down
13 changes: 7 additions & 6 deletions src/utils/getQuestionProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ const getQuestionProps = ({sectionIndex, section, question, values, disabled, wa
metadata,
navigation = [],
introduction,
multiline = false
multiline = false,
disabled: disabledByDefault
} = question;

const questionName = section ? `${section.name}.${sectionIndex}.${name}.answer` : '';
const jump = section ? getNavigation({navigation, answers: values, section, initialValues, sections}) : '';
const show = jump?.action !== questionActions.HIDE;
const show = Object.prototype.hasOwnProperty.call(question, 'hide') ? false : jump?.action !== questionActions.HIDE;
const isDisabled = jump?.action === questionActions.DISABLE || disabled;
let props;
switch (type) {
Expand All @@ -35,7 +36,7 @@ const getQuestionProps = ({sectionIndex, section, question, values, disabled, wa
placeholder: !placeholder && isNumericOrCurrency(type) ? 'Ingrese Valor' : placeholder,
name: questionName,
type: [questionTypes.TEXT_FIELD, questionTypes.CURRENCY].includes(type) ? 'text' : 'number',
disabled: isDisabled,
disabled: disabledByDefault || isDisabled,
warnings,
isMultiple: multiple,
values: values[name],
Expand All @@ -50,7 +51,7 @@ const getQuestionProps = ({sectionIndex, section, question, values, disabled, wa
placeholder,
name: questionName,
options,
disabled: isDisabled,
disabled: disabledByDefault || isDisabled,
isMultiple: multiple,
warnings,
values: values[name],
Expand All @@ -65,7 +66,7 @@ const getQuestionProps = ({sectionIndex, section, question, values, disabled, wa
label: {text: label, number, introduction},
name: questionName,
options,
disabled: isDisabled,
disabled: disabledByDefault || isDisabled,
isMultiple: multiple,
warnings,
values: values[name],
Expand All @@ -78,7 +79,7 @@ const getQuestionProps = ({sectionIndex, section, question, values, disabled, wa
label: {text: label, number, introduction},
placeholder,
name: questionName,
disabled: isDisabled,
disabled: disabledByDefault || isDisabled,
isMultiple: multiple,
metadata,
warnings,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/propTypes/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default PropTypes.shape({
introduction: PropTypes.string,
type: PropTypes.number.isRequired,
placeholder: PropTypes.string,
subQuestions: PropTypes.arrayOf(subQuestion)
subQuestions: PropTypes.arrayOf(subQuestion),
disabled: PropTypes.bool,
hide: PropTypes.bool
})
),
multiple: PropTypes.bool.isRequired,
Expand Down

0 comments on commit 0c35f98

Please sign in to comment.