Skip to content

Commit

Permalink
[#556] Handle show as larger input field in the form
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Dec 23, 2024
1 parent 1186d0f commit 0a6b8d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
42 changes: 26 additions & 16 deletions frontend/src/akvo-react-form/fields/TypeInput.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useEffect, useState, useMemo } from "react";
import { Form, Input } from "antd";
import TextArea from "antd/lib/input/TextArea";
import { Extra, FieldLabel, RepeatTableView } from "../support";
import GlobalStore from "../lib/store";
import { InputFieldIcon } from "../lib/svgIcons";
Expand All @@ -23,6 +24,7 @@ const InputField = ({
setShowPrefix,
naChecked,
currentValue,
show_as_textarea,
}) => (
<Form.Item
className="arf-field-child"
Expand Down Expand Up @@ -51,22 +53,26 @@ const InputField = ({
]}
required={coreMandatory ? required : !naChecked ? required : false}
>
<Input
style={{ width: "100%" }}
onBlur={() => {
setShowPrefix((prev) => prev.filter((p) => p !== id));
}}
onFocus={() => setShowPrefix((prev) => [...prev, id])}
onChange={onChange}
addonAfter={addonAfter}
addonBefore={addonBefore}
prefix={
fieldIcons &&
!showPrefix?.includes(id) &&
!currentValue && <InputFieldIcon />
}
disabled={naChecked || is_repeat_identifier} // handle leading_question -> is_repeat_identifier
/>
{show_as_textarea ? (
<TextArea row={4} disabled={naChecked || is_repeat_identifier} />
) : (
<Input
style={{ width: "100%" }}
onBlur={() => {
setShowPrefix((prev) => prev.filter((p) => p !== id));
}}
onFocus={() => setShowPrefix((prev) => [...prev, id])}
onChange={onChange}
addonAfter={addonAfter}
addonBefore={addonBefore}
prefix={
fieldIcons &&
!showPrefix?.includes(id) &&
!currentValue && <InputFieldIcon />
}
disabled={naChecked || is_repeat_identifier} // handle leading_question -> is_repeat_identifier
/>
)}
</Form.Item>
);

Expand All @@ -89,6 +95,7 @@ const TypeInput = ({
is_repeat_identifier,
show_repeat_as_table,
repeats,
show_as_textarea,
}) => {
const form = Form.useFormInstance();
const [showPrefix, setShowPrefix] = useState([]);
Expand Down Expand Up @@ -171,6 +178,7 @@ const TypeInput = ({
setShowPrefix={setShowPrefix}
naChecked={naChecked}
currentValue={currentValue}
show_as_textarea={show_as_textarea}
/>
),
};
Expand All @@ -192,6 +200,7 @@ const TypeInput = ({
rules,
showPrefix,
uiText,
show_as_textarea,
]);

return (
Expand Down Expand Up @@ -232,6 +241,7 @@ const TypeInput = ({
setShowPrefix={setShowPrefix}
naChecked={naChecked}
currentValue={currentValue}
show_as_textarea={show_as_textarea}
/>
)}
{/* EOL Show as repeat inputs or not */}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/survey-editor/Preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const Preview = () => {
member_access: qMemberAccess,
isco_access: qIscoAccess,
is_repeat_identifier: q?.is_repeat_identifier || false,
show_as_textarea: q?.show_as_textarea || false,
// add comment field
extra: [
{
Expand Down

0 comments on commit 0a6b8d8

Please sign in to comment.