Add CEP autocompletion by ViaCEP/ECT
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
feaebdf655
commit
33d9fe8688
1 file changed
+2
-1
@@ -562,6 +562,7 @@ export const ClienteModal: React.FC<ClienteModalProps> = ({
|
|||||||
error={errors.cep?.message}
|
error={errors.cep?.message}
|
||||||
placeholder="00000-000"
|
placeholder="00000-000"
|
||||||
maxLength={9}
|
maxLength={9}
|
||||||
|
value={watch("cep") || ""}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
// Formatação automática do CEP (00000-000)
|
// Formatação automática do CEP (00000-000)
|
||||||
let value = e.target.value.replace(/\D/g, "");
|
let value = e.target.value.replace(/\D/g, "");
|
||||||
@@ -571,7 +572,7 @@ export const ClienteModal: React.FC<ClienteModalProps> = ({
|
|||||||
"-" +
|
"-" +
|
||||||
value.substring(5, 8);
|
value.substring(5, 8);
|
||||||
}
|
}
|
||||||
e.target.value = value;
|
setValue("cep", value, { shouldValidate: true });
|
||||||
}}
|
}}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
// Forçar busca ao sair do campo
|
// Forçar busca ao sair do campo
|
||||||
|
|||||||
Reference in new issue
Block a user