mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 08:18:51 -06:00
web: Sync TextInputRow value with initialValue changes
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import formStyles from "./Form.module.css";
|
import formStyles from "./Form.module.css";
|
||||||
import HelpButton from "../Buttons/HelpButton";
|
import HelpButton from "../Buttons/HelpButton";
|
||||||
import React, { useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { ValidationError } from "../../../core/Data/validate";
|
import { ValidationError } from "../../../core/Data/validate";
|
||||||
|
|
||||||
interface TextInputRowProps {
|
interface TextInputRowProps {
|
||||||
@@ -21,6 +21,13 @@ function TextInputRow(props: TextInputRowProps) {
|
|||||||
const [savedValue, setSavedValue] = useState(props.initialValue);
|
const [savedValue, setSavedValue] = useState(props.initialValue);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (inputRef.current) {
|
||||||
|
inputRef.current.value = props.initialValue;
|
||||||
|
}
|
||||||
|
setSavedValue(props.initialValue);
|
||||||
|
}, [props.initialValue]);
|
||||||
|
|
||||||
const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
|
const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
if (newValue === savedValue) return;
|
if (newValue === savedValue) return;
|
||||||
@@ -29,8 +36,8 @@ function TextInputRow(props: TextInputRowProps) {
|
|||||||
inputRef.current!.value = savedValue;
|
inputRef.current!.value = savedValue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSavedValue(newValue);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={formStyles.FormRow}>
|
<div className={formStyles.FormRow}>
|
||||||
<label>
|
<label>
|
||||||
|
|||||||
Reference in New Issue
Block a user