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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b033c3a47f35de6f8b7ffc146e271bb47b1deacd8907d26ce7a2b0d53f5cbb21
4
- data.tar.gz: 20e3e4fc5b7c06a0dca8af5bc6fec8896d4747ca44a6bb54fa20a19231414ba6
3
+ metadata.gz: bd8b63915fa51f6daabd0a877e7bd6c0dbe337c900389228dd9434f5deeaa535
4
+ data.tar.gz: 1ba2091df0504ec326221fd2660e9238e7220673385b159e0c207ad82fb28e35
5
5
  SHA512:
6
- metadata.gz: 0a6b71fd848f702853c207858e87c9871452ddc33c47302f3b2f088b89e3a60a43a444c4b38a063dee98417471972969e46ca6be3b0bad682f414c8e32d282bd
7
- data.tar.gz: 36223f09387c0edc8f0e101568abae69bb1554525e3cf0e616d7cd3086ddcf4bce8994f6bc118fc6b64ad7e11bd02162a438fa03daa6f6ea023913b007d18446
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
- const handleInvalid = (event: Event) => {
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
- isValid(itiRef.current.isValidNumber())
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
- isValid(telInputInit.isValidNumber())
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
  },