Closed ahmed3hamdan closed 4 years ago
This behavior can be fixed by using "onKeyPress" to prevent the form from being submittied
import React from "react";
import ChipInput from "material-ui-chip-input";
const MyForm = () => {
const handleSubmit = e => {
e.preventDefault();
console.log("submitted");
};
const handleKeyPress = e => {
if (e.key === "Enter") e.preventDefault();
};
return (
<form onSubmit={handleSubmit}>
<ChipInput onKeyPress={handleKeyPress} onBeforeAdd={value => value.length >= 3} />
</form>
);
};
export default MyForm;
In the following example, the form is being submitted when adding a value less than 3 characters long
My solution to overcome the issue: