playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12653 → 15.5.0.pre.alpha.PLAY2581aggressivevalidation12654
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 +6 -35
- data/dist/chunks/{_typeahead-DLFhGsZU.js → _typeahead-Bbgw3Q5E.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: 8d7304b03db9bc4ab776ed9ce2604fe575e567e1422f9d5723bd21d5c70c7055
|
|
4
|
+
data.tar.gz: 13a59f20b961605878db38e672e12506f237cc84fc551f25362c6903cde1eb03
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4598269558bc2d5ba6477f6960b79cf9ba382cccf3d3aff365593dd191eb02848f0c04ac01b5e387f5a002378cf60d009e764e94dafb49247457c8daa3576de0
|
|
7
|
+
data.tar.gz: 9b79bf1cd0d95cafee125db473de79c58063ef9520172531f6be7e91eba01248d6e0a41cfb49449ebcd2ed20f576764e20931704c86df2bb017d0a7e7d6c8884
|
|
@@ -112,19 +112,14 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
112
112
|
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
113
113
|
const hasBlurredRef = useRef<boolean>(false);
|
|
114
114
|
const formSubmittedRef = useRef<boolean>(false);
|
|
115
|
-
|
|
116
|
-
const getValueString = (val: any): string => {
|
|
117
|
-
if (typeof val === 'string') return val
|
|
118
|
-
if (val?.number) return val.number
|
|
119
|
-
return ""
|
|
120
|
-
}
|
|
121
|
-
const [inputValue, setInputValue] = useState(getValueString(value))
|
|
115
|
+
const [inputValue, setInputValue] = useState(value)
|
|
122
116
|
const [error, setError] = useState(props.error || "")
|
|
123
117
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
|
124
118
|
const [selectedData, setSelectedData] = useState()
|
|
125
119
|
const [hasTyped, setHasTyped] = useState(false)
|
|
126
120
|
const [hasBlurred, setHasBlurred] = useState(false)
|
|
127
121
|
const [formSubmitted, setFormSubmitted] = useState(false)
|
|
122
|
+
const [hasStartedValidating, setHasStartedValidating] = useState(false)
|
|
128
123
|
|
|
129
124
|
// Keep refs in sync with state for use in event listeners
|
|
130
125
|
useEffect(() => {
|
|
@@ -134,16 +129,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
134
129
|
useEffect(() => {
|
|
135
130
|
formSubmittedRef.current = formSubmitted
|
|
136
131
|
}, [formSubmitted])
|
|
137
|
-
const [hasStartedValidating, setHasStartedValidating] = useState(false)
|
|
138
|
-
|
|
139
|
-
// Sync value prop when it changes (e.g., from react-hook-form)
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
const newValue = getValueString(props.value)
|
|
142
|
-
if (newValue !== inputValue) {
|
|
143
|
-
setInputValue(newValue)
|
|
144
|
-
}
|
|
145
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
146
|
-
}, [props.value])
|
|
147
132
|
|
|
148
133
|
// Only sync initial error from props, not continuous updates
|
|
149
134
|
// Once validation starts, internal validation takes over
|
|
@@ -173,10 +158,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
173
158
|
// Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
|
|
174
159
|
const shouldShowInternalError = (hasBlurred || formSubmitted) && error
|
|
175
160
|
const displayError = shouldShowInternalError ? error : ""
|
|
176
|
-
|
|
177
|
-
// Only show error prop after blur (to prevent showing react-hook-form errors while typing)
|
|
178
|
-
const shouldShowPropError = hasBlurred || formSubmitted
|
|
179
|
-
const propError = shouldShowPropError ? (props.error || "") : ""
|
|
180
161
|
|
|
181
162
|
useEffect(() => {
|
|
182
163
|
const hasError = (error ?? '').length > 0
|
|
@@ -291,7 +272,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
291
272
|
}
|
|
292
273
|
|
|
293
274
|
// Only validate if field has been blurred or form has been submitted
|
|
294
|
-
// Don't validate on change - only on blur or submission
|
|
295
275
|
if (!hasBlurred && !formSubmitted) return
|
|
296
276
|
|
|
297
277
|
// Run validation checks
|
|
@@ -306,7 +286,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
306
286
|
|
|
307
287
|
// Add listener for form validation to track when validation should be shown
|
|
308
288
|
useEffect(() => {
|
|
309
|
-
|
|
289
|
+
const handleInvalid = (event: Event) => {
|
|
310
290
|
const target = event.target as HTMLInputElement
|
|
311
291
|
const phoneNumberContainer = target.closest('.pb_phone_number_input')
|
|
312
292
|
|
|
@@ -444,12 +424,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
444
424
|
setFormSubmitted(false)
|
|
445
425
|
}
|
|
446
426
|
|
|
447
|
-
// Clear error when user starts typing (before blur)
|
|
448
|
-
// This prevents showing validation errors while typing
|
|
449
|
-
if (!hasBlurredRef.current && error) {
|
|
450
|
-
setError('')
|
|
451
|
-
}
|
|
452
|
-
|
|
453
427
|
let phoneNumberData
|
|
454
428
|
|
|
455
429
|
// Handle formatAsYouType with input event
|
|
@@ -465,6 +439,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
465
439
|
|
|
466
440
|
// Don't call isValid callback on change - only on blur or form submission
|
|
467
441
|
// This prevents triggering validation while typing
|
|
442
|
+
// Use refs to get current values in case this is called from event listener
|
|
468
443
|
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
469
444
|
isValid(itiRef.current.isValidNumber())
|
|
470
445
|
}
|
|
@@ -525,11 +500,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
525
500
|
setInputValue(formattedValue)
|
|
526
501
|
setHasTyped(true)
|
|
527
502
|
|
|
528
|
-
// Clear error when user types (before blur) - use ref to get current value
|
|
529
|
-
if (!hasBlurredRef.current) {
|
|
530
|
-
setError('')
|
|
531
|
-
}
|
|
532
|
-
|
|
533
503
|
// Get phone number data with unformatted number
|
|
534
504
|
const formattedPhoneNumberData = getCurrentSelectedData(telInputInit, formattedValue)
|
|
535
505
|
const phoneNumberData = {...formattedPhoneNumberData, number: unformatNumber(formattedPhoneNumberData.number)}
|
|
@@ -538,6 +508,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
538
508
|
onChange(phoneNumberData)
|
|
539
509
|
|
|
540
510
|
// Don't call isValid callback on change - only on blur or form submission
|
|
511
|
+
// Use refs to check current blur state in the event listener (closure issue)
|
|
541
512
|
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
542
513
|
isValid(telInputInit.isValidNumber())
|
|
543
514
|
}
|
|
@@ -550,7 +521,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
550
521
|
dark,
|
|
551
522
|
"data-phone-number": JSON.stringify(selectedData),
|
|
552
523
|
disabled,
|
|
553
|
-
error: displayError ||
|
|
524
|
+
error: displayError || props.error || "",
|
|
554
525
|
type: 'tel',
|
|
555
526
|
id,
|
|
556
527
|
label,
|