I am encountering an issue with input fields in my React app. When I try to replace a default value in the input field (e.g., "0" or "1"), I am unable to completely clear the value. Specifically, I cannot delete the first character (whether it's a number or letter). For example:
If the input is "USD" by default and I try to replace it with "SGD", I cannot delete the "U" and the input still shows "USD" or "0120" when trying to type "120" instead of "0".
This happens across multiple input fields, whether I am trying to replace numeric values (e.g., 1 to 120) or currency symbols (e.g., USD to EUR).
<div className="alert-devise-choice">
<label htmlFor="symbol" className="alert-deviseLabel">Choisir une devise:</label>
<input
type="text"
id="symbol"
value={symbol}
onChange={(e) => handleChange("symbol", e.target.value)}
className="alert-devise-input"
required
autoComplete="off"
/>
</div>
{errors.symbol && <small className="error-message">{errors.symbol}</small>}
const handleChange = (field, value) => {
let updatedErrors = { ...errors};
if (field === 'symbol') { const isNumeric = !isNaN(value); const validSymbols = filteredDevises.map(devise => devise.symbol); const isInList = validSymbols.includes(value.toUpperCase()); if (isNumeric) { updatedErrors.symbol = "Please enter a valid currency symbol."; } else { updatedErrors.symbol = ""; setSymbol(value); // or however you store the selected symbol } } if (field === 'valueLimit') { if (isNaN(value) || value < 0.1) { updatedErrors.valueLimit = "Value limit must be a number and at least 0.1."; } else { updatedErrors.valueLimit = ""; setValueLimit(value); } }
setErrors(updatedErrors); };