playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12652 → 15.5.0.pre.alpha.PLAY2581aggressivevalidation12653
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 +41 -3
- data/dist/chunks/{_typeahead-C4h8SiWS.js → _typeahead-DLFhGsZU.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: bd8b63915fa51f6daabd0a877e7bd6c0dbe337c900389228dd9434f5deeaa535
|
|
4
|
+
data.tar.gz: 1ba2091df0504ec326221fd2660e9238e7220673385b159e0c207ad82fb28e35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 212923b88fdcc63bd98592cc373ff989b51f237d1d147b6fb5f083e15b521812e7a06d9f9ee54f2b1ccf16edf3160ee94e6b28f81a10caf5bcbcee59b731774d
|
|
7
|
+
data.tar.gz: 8ee030cb7e451dae0bedec3d130b94ae4607ce49037f95c4901ce02a755eb054829734682c1d46c067cca2955da6272baa46c741cc1124b4be94b2fddb64859f
|
|
@@ -110,6 +110,8 @@ 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
|
+
const hasBlurredRef = useRef<boolean>(false);
|
|
114
|
+
const formSubmittedRef = useRef<boolean>(false);
|
|
113
115
|
// Handle value prop - it might be a string or an object with number property (from react-hook-form)
|
|
114
116
|
const getValueString = (val: any): string => {
|
|
115
117
|
if (typeof val === 'string') return val
|
|
@@ -123,6 +125,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
123
125
|
const [hasTyped, setHasTyped] = useState(false)
|
|
124
126
|
const [hasBlurred, setHasBlurred] = useState(false)
|
|
125
127
|
const [formSubmitted, setFormSubmitted] = useState(false)
|
|
128
|
+
|
|
129
|
+
// Keep refs in sync with state for use in event listeners
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
hasBlurredRef.current = hasBlurred
|
|
132
|
+
}, [hasBlurred])
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
formSubmittedRef.current = formSubmitted
|
|
136
|
+
}, [formSubmitted])
|
|
126
137
|
const [hasStartedValidating, setHasStartedValidating] = useState(false)
|
|
127
138
|
|
|
128
139
|
// Sync value prop when it changes (e.g., from react-hook-form)
|
|
@@ -295,13 +306,14 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
295
306
|
|
|
296
307
|
// Add listener for form validation to track when validation should be shown
|
|
297
308
|
useEffect(() => {
|
|
298
|
-
|
|
309
|
+
const handleInvalid = (event: Event) => {
|
|
299
310
|
const target = event.target as HTMLInputElement
|
|
300
311
|
const phoneNumberContainer = target.closest('.pb_phone_number_input')
|
|
301
312
|
|
|
302
313
|
if (phoneNumberContainer && phoneNumberContainer === wrapperRef.current) {
|
|
303
314
|
const invalidInputName = target.name || target.getAttribute('name')
|
|
304
315
|
if (invalidInputName === name) {
|
|
316
|
+
formSubmittedRef.current = true
|
|
305
317
|
setFormSubmitted(true)
|
|
306
318
|
// Trigger validation when form is submitted
|
|
307
319
|
validateErrors()
|
|
@@ -327,7 +339,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
327
339
|
setInputValue("")
|
|
328
340
|
setError("")
|
|
329
341
|
setHasTyped(false)
|
|
342
|
+
hasBlurredRef.current = false
|
|
330
343
|
setHasBlurred(false)
|
|
344
|
+
formSubmittedRef.current = false
|
|
331
345
|
setFormSubmitted(false)
|
|
332
346
|
setHasStartedValidating(false)
|
|
333
347
|
// Only clear validation state if field was required
|
|
@@ -345,6 +359,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
345
359
|
|
|
346
360
|
if (required && isEmpty) {
|
|
347
361
|
setError('Missing phone number')
|
|
362
|
+
formSubmittedRef.current = true
|
|
348
363
|
setFormSubmitted(true)
|
|
349
364
|
return 'Missing phone number'
|
|
350
365
|
}
|
|
@@ -401,6 +416,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
401
416
|
|
|
402
417
|
// Set the error state so the validation attribute gets added
|
|
403
418
|
setError(errorMessage)
|
|
419
|
+
formSubmittedRef.current = true
|
|
404
420
|
setFormSubmitted(true)
|
|
405
421
|
setHasTyped(true)
|
|
406
422
|
|
|
@@ -424,9 +440,16 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
424
440
|
|
|
425
441
|
// Reset form submitted state when user types
|
|
426
442
|
if (formSubmitted) {
|
|
443
|
+
formSubmittedRef.current = false
|
|
427
444
|
setFormSubmitted(false)
|
|
428
445
|
}
|
|
429
446
|
|
|
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
|
+
|
|
430
453
|
let phoneNumberData
|
|
431
454
|
|
|
432
455
|
// Handle formatAsYouType with input event
|
|
@@ -439,7 +462,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
439
462
|
|
|
440
463
|
setSelectedData(phoneNumberData)
|
|
441
464
|
onChange(phoneNumberData)
|
|
442
|
-
|
|
465
|
+
|
|
466
|
+
// Don't call isValid callback on change - only on blur or form submission
|
|
467
|
+
// This prevents triggering validation while typing
|
|
468
|
+
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
469
|
+
isValid(itiRef.current.isValidNumber())
|
|
470
|
+
}
|
|
443
471
|
|
|
444
472
|
// Don't validate on change - only validate on blur or form submission
|
|
445
473
|
}
|
|
@@ -497,13 +525,22 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
497
525
|
setInputValue(formattedValue)
|
|
498
526
|
setHasTyped(true)
|
|
499
527
|
|
|
528
|
+
// Clear error when user types (before blur) - use ref to get current value
|
|
529
|
+
if (!hasBlurredRef.current) {
|
|
530
|
+
setError('')
|
|
531
|
+
}
|
|
532
|
+
|
|
500
533
|
// Get phone number data with unformatted number
|
|
501
534
|
const formattedPhoneNumberData = getCurrentSelectedData(telInputInit, formattedValue)
|
|
502
535
|
const phoneNumberData = {...formattedPhoneNumberData, number: unformatNumber(formattedPhoneNumberData.number)}
|
|
503
536
|
|
|
504
537
|
setSelectedData(phoneNumberData)
|
|
505
538
|
onChange(phoneNumberData)
|
|
506
|
-
|
|
539
|
+
|
|
540
|
+
// Don't call isValid callback on change - only on blur or form submission
|
|
541
|
+
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
542
|
+
isValid(telInputInit.isValidNumber())
|
|
543
|
+
}
|
|
507
544
|
})
|
|
508
545
|
}
|
|
509
546
|
}
|
|
@@ -519,6 +556,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
519
556
|
label,
|
|
520
557
|
name,
|
|
521
558
|
onBlur: () => {
|
|
559
|
+
hasBlurredRef.current = true
|
|
522
560
|
setHasBlurred(true)
|
|
523
561
|
validateErrors()
|
|
524
562
|
},
|