react-places-autocomplete
react-places-autocomplete copied to clipboard
PlacesAutoComplete skips the first character when typing in with required.
I used MUI to wrap this package. And it's a required field. When I press submit if shows required filed error, that's okay. But when I press any character like 'a' or any it does not displays it. But it only removes the required error. When I type a character again it shows up.
<PlacesAutocomplete searchOptions={{ types: ["(regions)"], componentRestrictions: { country: "us" }, }} value={zipCode} ref={(ref) => (canvasRef = ref)} onChange={setZipCode} onSelect={handleSelect} > {({ getInputProps, suggestions, getSuggestionItemProps, loading, }) => (
{formData.zip === null && onSubmitFlag && (
<span className="error">
{_resources.PatientInformation.ZIP_REQUIRED}
</span>
)}
<div className="autocomplete-dropdown-container">
{loading ? (
<Spin
className="m-auto plcs-auto-complete-spinner"
indicator={antIcon}
/>
) : null}
{suggestions.map((suggestion, index) => {
const style = {
backgroundColor: suggestion.active ? "#41b6e6" : "#fff",
borderTop: "1px solid #00504633",
paddingTop: "1px",
paddingBottom: "1px",
};
return (
<div
key={index}
className="suggestions"
{...getSuggestionItemProps(suggestion, { style })}
>
<img
src={clinicIcon}
className="suggestions-location-icon icon-location"
alt="clinic-icon"
/>
{suggestion.description.slice(0, 60)}
</div>
);
})}
</div>
</div>
)}
</PlacesAutocomplete>
I found out, it is related to react-hook-forms. For more information check this out
https://react-hook-form.com/faqs#Whyisthefirstkeystrokenotworking