playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12650 → 15.5.0.pre.alpha.PLAY2581aggressivevalidation12652
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.tsx +24 -4
- data/dist/chunks/{_typeahead-Dkq7BPdu.js → _typeahead-C4h8SiWS.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b033c3a47f35de6f8b7ffc146e271bb47b1deacd8907d26ce7a2b0d53f5cbb21
|
|
4
|
+
data.tar.gz: 20e3e4fc5b7c06a0dca8af5bc6fec8896d4747ca44a6bb54fa20a19231414ba6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a6b71fd848f702853c207858e87c9871452ddc33c47302f3b2f088b89e3a60a43a444c4b38a063dee98417471972969e46ca6be3b0bad682f414c8e32d282bd
|
|
7
|
+
data.tar.gz: 36223f09387c0edc8f0e101568abae69bb1554525e3cf0e616d7cd3086ddcf4bce8994f6bc118fc6b64ad7e11bd02162a438fa03daa6f6ea023913b007d18446
|
|
@@ -110,7 +110,13 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
110
110
|
const inputRef = useRef<HTMLInputElement | null>(null)
|
|
111
111
|
const itiRef = useRef<any>(null);
|
|
112
112
|
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
113
|
-
|
|
113
|
+
// Handle value prop - it might be a string or an object with number property (from react-hook-form)
|
|
114
|
+
const getValueString = (val: any): string => {
|
|
115
|
+
if (typeof val === 'string') return val
|
|
116
|
+
if (val?.number) return val.number
|
|
117
|
+
return ""
|
|
118
|
+
}
|
|
119
|
+
const [inputValue, setInputValue] = useState(getValueString(value))
|
|
114
120
|
const [error, setError] = useState(props.error || "")
|
|
115
121
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
|
116
122
|
const [selectedData, setSelectedData] = useState()
|
|
@@ -119,6 +125,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
119
125
|
const [formSubmitted, setFormSubmitted] = useState(false)
|
|
120
126
|
const [hasStartedValidating, setHasStartedValidating] = useState(false)
|
|
121
127
|
|
|
128
|
+
// Sync value prop when it changes (e.g., from react-hook-form)
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const newValue = getValueString(props.value)
|
|
131
|
+
if (newValue !== inputValue) {
|
|
132
|
+
setInputValue(newValue)
|
|
133
|
+
}
|
|
134
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
135
|
+
}, [props.value])
|
|
136
|
+
|
|
122
137
|
// Only sync initial error from props, not continuous updates
|
|
123
138
|
// Once validation starts, internal validation takes over
|
|
124
139
|
useEffect(() => {
|
|
@@ -147,6 +162,10 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
147
162
|
// Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
|
|
148
163
|
const shouldShowInternalError = (hasBlurred || formSubmitted) && error
|
|
149
164
|
const displayError = shouldShowInternalError ? error : ""
|
|
165
|
+
|
|
166
|
+
// Only show error prop after blur (to prevent showing react-hook-form errors while typing)
|
|
167
|
+
const shouldShowPropError = hasBlurred || formSubmitted
|
|
168
|
+
const propError = shouldShowPropError ? (props.error || "") : ""
|
|
150
169
|
|
|
151
170
|
useEffect(() => {
|
|
152
171
|
const hasError = (error ?? '').length > 0
|
|
@@ -261,7 +280,8 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
261
280
|
}
|
|
262
281
|
|
|
263
282
|
// Only validate if field has been blurred or form has been submitted
|
|
264
|
-
|
|
283
|
+
// Don't validate on change - only on blur or submission
|
|
284
|
+
if (!hasBlurred && !formSubmitted) return
|
|
265
285
|
|
|
266
286
|
// Run validation checks
|
|
267
287
|
if (itiRef.current) isValid(itiRef.current.isValidNumber())
|
|
@@ -493,12 +513,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
493
513
|
dark,
|
|
494
514
|
"data-phone-number": JSON.stringify(selectedData),
|
|
495
515
|
disabled,
|
|
496
|
-
error:
|
|
516
|
+
error: displayError || propError,
|
|
497
517
|
type: 'tel',
|
|
498
518
|
id,
|
|
499
519
|
label,
|
|
500
520
|
name,
|
|
501
|
-
onBlur: (
|
|
521
|
+
onBlur: () => {
|
|
502
522
|
setHasBlurred(true)
|
|
503
523
|
validateErrors()
|
|
504
524
|
},
|