I'm using react material ui with this Textfield:
<TextField
required
id="qty"
type="number"
label="Qtà"
defaultValue={!props.row.qty ? '1.00' : props.row.qty}
step={1.00}
variant="outlined"
error={HP_qty.length === 0 ? false : true}
helperText={HP_qty}
inputProps={{
maxLength: 13,
}}
onBlur={(e) => onBlur(e,HP_qty)}/>
I would like to use the arrows in order to have a 1.00 step so on 1.00 as a default number i can visualize the 2.00 or the 0.00 number. the result for now is: 1.00 -> (arrow up) -> 2 so basically it removes zeros that I would like to have.
Use controlled TextField
and format the number every time change
event fires. See this answer.
Also note that the value displayed in the TextField
is now a string so you may want to convert it back to number before submitting your changes.
function App() {
const [value, setValue] = useState("0.0");
return (
<TextField
type="number"
value={value}
variant="outlined"
inputProps={{
maxLength: 13,
step: "1"
}}
onChange={(e) => setValue(parseFloat(e.target.value).toFixed(1))}
/>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With