playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12651 → 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 +43 -4
- data/dist/chunks/{_typeahead-DrZthFaf.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)
|
|
@@ -280,7 +291,8 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
280
291
|
}
|
|
281
292
|
|
|
282
293
|
// Only validate if field has been blurred or form has been submitted
|
|
283
|
-
|
|
294
|
+
// Don't validate on change - only on blur or submission
|
|
295
|
+
if (!hasBlurred && !formSubmitted) return
|
|
284
296
|
|
|
285
297
|
// Run validation checks
|
|
286
298
|
if (itiRef.current) isValid(itiRef.current.isValidNumber())
|
|
@@ -294,13 +306,14 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
294
306
|
|
|
295
307
|
// Add listener for form validation to track when validation should be shown
|
|
296
308
|
useEffect(() => {
|
|
297
|
-
|
|
309
|
+
const handleInvalid = (event: Event) => {
|
|
298
310
|
const target = event.target as HTMLInputElement
|
|
299
311
|
const phoneNumberContainer = target.closest('.pb_phone_number_input')
|
|
300
312
|
|
|
301
313
|
if (phoneNumberContainer && phoneNumberContainer === wrapperRef.current) {
|
|
302
314
|
const invalidInputName = target.name || target.getAttribute('name')
|
|
303
315
|
if (invalidInputName === name) {
|
|
316
|
+
formSubmittedRef.current = true
|
|
304
317
|
setFormSubmitted(true)
|
|
305
318
|
// Trigger validation when form is submitted
|
|
306
319
|
validateErrors()
|
|
@@ -326,7 +339,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
326
339
|
setInputValue("")
|
|
327
340
|
setError("")
|
|
328
341
|
setHasTyped(false)
|
|
342
|
+
hasBlurredRef.current = false
|
|
329
343
|
setHasBlurred(false)
|
|
344
|
+
formSubmittedRef.current = false
|
|
330
345
|
setFormSubmitted(false)
|
|
331
346
|
setHasStartedValidating(false)
|
|
332
347
|
// Only clear validation state if field was required
|
|
@@ -344,6 +359,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
344
359
|
|
|
345
360
|
if (required && isEmpty) {
|
|
346
361
|
setError('Missing phone number')
|
|
362
|
+
formSubmittedRef.current = true
|
|
347
363
|
setFormSubmitted(true)
|
|
348
364
|
return 'Missing phone number'
|
|
349
365
|
}
|
|
@@ -400,6 +416,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
400
416
|
|
|
401
417
|
// Set the error state so the validation attribute gets added
|
|
402
418
|
setError(errorMessage)
|
|
419
|
+
formSubmittedRef.current = true
|
|
403
420
|
setFormSubmitted(true)
|
|
404
421
|
setHasTyped(true)
|
|
405
422
|
|
|
@@ -423,9 +440,16 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
423
440
|
|
|
424
441
|
// Reset form submitted state when user types
|
|
425
442
|
if (formSubmitted) {
|
|
443
|
+
formSubmittedRef.current = false
|
|
426
444
|
setFormSubmitted(false)
|
|
427
445
|
}
|
|
428
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
|
+
|
|
429
453
|
let phoneNumberData
|
|
430
454
|
|
|
431
455
|
// Handle formatAsYouType with input event
|
|
@@ -438,7 +462,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
438
462
|
|
|
439
463
|
setSelectedData(phoneNumberData)
|
|
440
464
|
onChange(phoneNumberData)
|
|
441
|
-
|
|
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
|
+
}
|
|
442
471
|
|
|
443
472
|
// Don't validate on change - only validate on blur or form submission
|
|
444
473
|
}
|
|
@@ -496,13 +525,22 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
496
525
|
setInputValue(formattedValue)
|
|
497
526
|
setHasTyped(true)
|
|
498
527
|
|
|
528
|
+
// Clear error when user types (before blur) - use ref to get current value
|
|
529
|
+
if (!hasBlurredRef.current) {
|
|
530
|
+
setError('')
|
|
531
|
+
}
|
|
532
|
+
|
|
499
533
|
// Get phone number data with unformatted number
|
|
500
534
|
const formattedPhoneNumberData = getCurrentSelectedData(telInputInit, formattedValue)
|
|
501
535
|
const phoneNumberData = {...formattedPhoneNumberData, number: unformatNumber(formattedPhoneNumberData.number)}
|
|
502
536
|
|
|
503
537
|
setSelectedData(phoneNumberData)
|
|
504
538
|
onChange(phoneNumberData)
|
|
505
|
-
|
|
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
|
+
}
|
|
506
544
|
})
|
|
507
545
|
}
|
|
508
546
|
}
|
|
@@ -518,6 +556,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
518
556
|
label,
|
|
519
557
|
name,
|
|
520
558
|
onBlur: () => {
|
|
559
|
+
hasBlurredRef.current = true
|
|
521
560
|
setHasBlurred(true)
|
|
522
561
|
validateErrors()
|
|
523
562
|
},
|