playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12652 → 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 +32 -23
- data/dist/chunks/{_typeahead-C4h8SiWS.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
|
|
@@ -110,13 +110,9 @@ 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
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
if (val?.number) return val.number
|
|
117
|
-
return ""
|
|
118
|
-
}
|
|
119
|
-
const [inputValue, setInputValue] = useState(getValueString(value))
|
|
113
|
+
const hasBlurredRef = useRef<boolean>(false);
|
|
114
|
+
const formSubmittedRef = useRef<boolean>(false);
|
|
115
|
+
const [inputValue, setInputValue] = useState(value)
|
|
120
116
|
const [error, setError] = useState(props.error || "")
|
|
121
117
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
|
122
118
|
const [selectedData, setSelectedData] = useState()
|
|
@@ -124,15 +120,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
124
120
|
const [hasBlurred, setHasBlurred] = useState(false)
|
|
125
121
|
const [formSubmitted, setFormSubmitted] = useState(false)
|
|
126
122
|
const [hasStartedValidating, setHasStartedValidating] = useState(false)
|
|
127
|
-
|
|
128
|
-
//
|
|
123
|
+
|
|
124
|
+
// Keep refs in sync with state for use in event listeners
|
|
129
125
|
useEffect(() => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}, [
|
|
126
|
+
hasBlurredRef.current = hasBlurred
|
|
127
|
+
}, [hasBlurred])
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
formSubmittedRef.current = formSubmitted
|
|
131
|
+
}, [formSubmitted])
|
|
136
132
|
|
|
137
133
|
// Only sync initial error from props, not continuous updates
|
|
138
134
|
// Once validation starts, internal validation takes over
|
|
@@ -162,10 +158,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
162
158
|
// Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
|
|
163
159
|
const shouldShowInternalError = (hasBlurred || formSubmitted) && error
|
|
164
160
|
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 || "") : ""
|
|
169
161
|
|
|
170
162
|
useEffect(() => {
|
|
171
163
|
const hasError = (error ?? '').length > 0
|
|
@@ -280,7 +272,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
280
272
|
}
|
|
281
273
|
|
|
282
274
|
// Only validate if field has been blurred or form has been submitted
|
|
283
|
-
// Don't validate on change - only on blur or submission
|
|
284
275
|
if (!hasBlurred && !formSubmitted) return
|
|
285
276
|
|
|
286
277
|
// Run validation checks
|
|
@@ -302,6 +293,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
302
293
|
if (phoneNumberContainer && phoneNumberContainer === wrapperRef.current) {
|
|
303
294
|
const invalidInputName = target.name || target.getAttribute('name')
|
|
304
295
|
if (invalidInputName === name) {
|
|
296
|
+
formSubmittedRef.current = true
|
|
305
297
|
setFormSubmitted(true)
|
|
306
298
|
// Trigger validation when form is submitted
|
|
307
299
|
validateErrors()
|
|
@@ -327,7 +319,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
327
319
|
setInputValue("")
|
|
328
320
|
setError("")
|
|
329
321
|
setHasTyped(false)
|
|
322
|
+
hasBlurredRef.current = false
|
|
330
323
|
setHasBlurred(false)
|
|
324
|
+
formSubmittedRef.current = false
|
|
331
325
|
setFormSubmitted(false)
|
|
332
326
|
setHasStartedValidating(false)
|
|
333
327
|
// Only clear validation state if field was required
|
|
@@ -345,6 +339,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
345
339
|
|
|
346
340
|
if (required && isEmpty) {
|
|
347
341
|
setError('Missing phone number')
|
|
342
|
+
formSubmittedRef.current = true
|
|
348
343
|
setFormSubmitted(true)
|
|
349
344
|
return 'Missing phone number'
|
|
350
345
|
}
|
|
@@ -401,6 +396,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
401
396
|
|
|
402
397
|
// Set the error state so the validation attribute gets added
|
|
403
398
|
setError(errorMessage)
|
|
399
|
+
formSubmittedRef.current = true
|
|
404
400
|
setFormSubmitted(true)
|
|
405
401
|
setHasTyped(true)
|
|
406
402
|
|
|
@@ -424,6 +420,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
424
420
|
|
|
425
421
|
// Reset form submitted state when user types
|
|
426
422
|
if (formSubmitted) {
|
|
423
|
+
formSubmittedRef.current = false
|
|
427
424
|
setFormSubmitted(false)
|
|
428
425
|
}
|
|
429
426
|
|
|
@@ -439,7 +436,13 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
439
436
|
|
|
440
437
|
setSelectedData(phoneNumberData)
|
|
441
438
|
onChange(phoneNumberData)
|
|
442
|
-
|
|
439
|
+
|
|
440
|
+
// Don't call isValid callback on change - only on blur or form submission
|
|
441
|
+
// This prevents triggering validation while typing
|
|
442
|
+
// Use refs to get current values in case this is called from event listener
|
|
443
|
+
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
444
|
+
isValid(itiRef.current.isValidNumber())
|
|
445
|
+
}
|
|
443
446
|
|
|
444
447
|
// Don't validate on change - only validate on blur or form submission
|
|
445
448
|
}
|
|
@@ -503,7 +506,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
503
506
|
|
|
504
507
|
setSelectedData(phoneNumberData)
|
|
505
508
|
onChange(phoneNumberData)
|
|
506
|
-
|
|
509
|
+
|
|
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)
|
|
512
|
+
if (hasBlurredRef.current || formSubmittedRef.current) {
|
|
513
|
+
isValid(telInputInit.isValidNumber())
|
|
514
|
+
}
|
|
507
515
|
})
|
|
508
516
|
}
|
|
509
517
|
}
|
|
@@ -513,12 +521,13 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
513
521
|
dark,
|
|
514
522
|
"data-phone-number": JSON.stringify(selectedData),
|
|
515
523
|
disabled,
|
|
516
|
-
error: displayError ||
|
|
524
|
+
error: displayError || props.error || "",
|
|
517
525
|
type: 'tel',
|
|
518
526
|
id,
|
|
519
527
|
label,
|
|
520
528
|
name,
|
|
521
529
|
onBlur: () => {
|
|
530
|
+
hasBlurredRef.current = true
|
|
522
531
|
setHasBlurred(true)
|
|
523
532
|
validateErrors()
|
|
524
533
|
},
|