Skip to content

Commit

Permalink
[#556] Add show as larger input field setting in question input
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Dec 23, 2024
1 parent 8e43f36 commit 1186d0f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/components/survey-editor/QuestionEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const QuestionEditor = ({
const [activeLang, setActiveLang] = useState(null);
const [allowNA, setAllowNA] = useState(false);
const [isRepeatIdentifierValue, setIsRepeatIdentifierValue] = useState(false);
const [showAsTextarea, setShowAsTextarea] = useState(false);

// handle when form languages updated
useEffect(() => {
Expand Down Expand Up @@ -252,6 +253,9 @@ const QuestionEditor = ({
if (key === "is_repeat_identifier") {
setIsRepeatIdentifierValue(value);
}
if (key === "show_as_textarea") {
setShowAsTextarea(value);
}
});
}
}, [question, form, qId]);
Expand Down Expand Up @@ -424,6 +428,8 @@ const QuestionEditor = ({
setAllowNA={setAllowNA}
isRepeatIdentifierValue={isRepeatIdentifierValue}
setIsRepeatIdentifierValue={setIsRepeatIdentifierValue}
showAsTextarea={showAsTextarea}
setShowAsTextarea={setShowAsTextarea}
/>
<div className="question-button-wrapper">
<Space align="center">
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/components/survey-editor/QuestionSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const QuestionSetting = ({
setAllowNA,
isRepeatIdentifierValue,
setIsRepeatIdentifierValue,
showAsTextarea,
setShowAsTextarea,
}) => {
const [deactivatePopconfirmMessage, setDeactivatePopconfirmMessage] =
useState("");
Expand Down Expand Up @@ -269,6 +271,14 @@ const QuestionSetting = ({
handleFormOnValuesChange(fieldValue, form?.getFieldsValue());
};

const handleShowAsTextareaChange = (val, field) => {
const { checked } = val.target;
const fieldValue = { [field]: checked };
form.setFieldsValue(fieldValue);
setShowAsTextarea(checked);
handleFormOnValuesChange(fieldValue, form?.getFieldsValue());
};

const handleDatapointNameChange = (val, field) => {
const { checked } = val.target;
const fieldValue = { [field]: checked };
Expand Down Expand Up @@ -542,6 +552,28 @@ const QuestionSetting = ({
/>
</div>
</Space>
{
// setting to show input question as text area
currentQuestionType === "input" && (
<div className="field-wrapper" style={{ marginTop: "20px" }}>
<Form.Item name={`question-${qid}-show_as_textarea`}>
<Checkbox
key={`question-${qid}-show_as_textarea-checkbox`}
checked={showAsTextarea}
onChange={(val) =>
handleShowAsTextareaChange(
val,
`question-${qid}-show_as_textarea`
)
}
>
{" "}
Show as larger input field{" "}
</Checkbox>
</Form.Item>
</div>
)
}
{
// Set question as datapoint/display name
datapointNameQuestionType.includes(currentQuestionType) && (
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/survey-editor/QuestionTabContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const QuestionTabContent = ({
setAllowNA,
isRepeatIdentifierValue,
setIsRepeatIdentifierValue,
showAsTextarea,
setShowAsTextarea,
}) => {
switch (activeSetting) {
case "translation":
Expand Down Expand Up @@ -63,6 +65,8 @@ const QuestionTabContent = ({
setAllowNA={setAllowNA}
isRepeatIdentifierValue={isRepeatIdentifierValue}
setIsRepeatIdentifierValue={setIsRepeatIdentifierValue}
showAsTextarea={showAsTextarea}
setShowAsTextarea={setShowAsTextarea}
/>
);
default:
Expand Down

0 comments on commit 1186d0f

Please sign in to comment.