fix: prevent phone input from running validation on mount when empty

This commit is contained in:
Simon Emanuelsson
2024-10-31 13:39:08 +01:00
parent eb0494c2a2
commit 46a1874a76
8 changed files with 56 additions and 35 deletions

View File

@@ -58,8 +58,14 @@ export default function Phone({
forceDialCode: true,
value: phone,
onChange: (value) => {
setValue(name, value.phone)
trigger(name)
// If not checked trigger(name) forces validation on mount
// which shows error message before user even can see the form
if (value.inputValue) {
setValue(name, value.phone)
trigger(name)
} else {
setValue(name, "")
}
},
})