Skip to content

Commit 81fa416

Browse files
committed
FormPage: fix displaying custom image
1 parent f8dbb71 commit 81fa416

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/FormPage.jsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@ const StepOne = ({ setFormData, defaultFormData }) => {
2929
const [checkSsh, setCheckSsh] = useState(null);
3030
const [selectedDropdownIndex, setSelectedDropdownIndex] = useState(null);
3131
const [activeDropdownOptionIndex, setActiveDropdownOptionIndex] = useState(null);
32+
const [customImageValue, setCustomImageValue] = useState(""); // New state for input field value
33+
3234

3335
useEffect(() => {
3436
if (defaultFormData && defaultFormData.notebookImage) {
3537

36-
const text = defaultFormData.notebookImage.type;
37-
if (text === "customnb") {
38-
handleInputChange({
39-
target: {
40-
value: defaultFormData.notebookImage.selectedOption,
41-
},
42-
}, Object.entries(images).length + 1)
43-
} else if (text === null){
38+
const text = defaultFormData.notebookImage.type;
39+
if (text === "customnb") {
40+
setCustomImageValue(defaultFormData.notebookImage.selectedOption); // Set initial value for input
41+
setActiveDropdownOptionIndex(null);
42+
setSelectedDropdownIndex(Object.entries(images).length + 1);
43+
setFormData((prev) => ({
44+
...prev,
45+
images: "custom",
46+
customimage: defaultFormData.notebookImage.selectedOption,
47+
}));
48+
} else if (text === null){
4449
return
4550
} else {
4651
const key = Object.keys(defaultImagesName).find((key) => defaultImagesName[key] === text);
@@ -71,12 +76,14 @@ const StepOne = ({ setFormData, defaultFormData }) => {
7176
};
7277

7378
const handleInputChange = (e, index) => {
79+
setCustomImageValue(e.target.value); // Update state on input change
7480
setActiveDropdownOptionIndex(null);
7581
setSelectedDropdownIndex(index);
82+
7683
setFormData((prev) => ({
7784
...prev,
7885
images: "custom",
79-
customimage: e.target.value,
86+
customimage: e.target.value, // Use the current input value
8087
}));
8188
};
8289

@@ -151,9 +158,8 @@ const StepOne = ({ setFormData, defaultFormData }) => {
151158
>
152159
<input
153160
type="text"
154-
onChange={(e) =>
155-
handleInputChange(e, Object.entries(images).length + 1)
156-
}
161+
value={customImageValue} // Bind input to state
162+
onChange={(e) => handleInputChange(e, Object.entries(images).length + 1)}
157163
placeholder="Write image name here"
158164
className="custom-option"
159165
/>

0 commit comments

Comments
 (0)