playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12650 → 15.5.0.pre.alpha.PLAY2581aggressivevalidation12651
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 +22 -3
- data/dist/chunks/{_typeahead-Dkq7BPdu.js → _typeahead-DrZthFaf.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: 7a11fd5c7d50218344f06ff233740c4b4fbd7821f77ae252ae36cb6b0a72891b
|
|
4
|
+
data.tar.gz: 34b091afe5eeb712931507289e02ea6f9fbc0476d6700340a3ce7f22d97a86ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98b2841f9f591ad23e05c8fc418e518672c6820abd5d338e4d7144f4b3900c91005ff00f1c7829a6e474428a5fe83224a5a3b6ef1c7bd527aad2cf9fddf8d95a
|
|
7
|
+
data.tar.gz: bee8426f2ca6a22dbd355427ec5d5f34fee41ce12752a0ecf78d14663f1be35b68fce6e0316ef4b2340632e011203302daac490c56a1eb177e92fdf3354893f9
|
|
@@ -110,7 +110,13 @@ 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
|
-
|
|
113
|
+
// Handle value prop - it might be a string or an object with number property (from react-hook-form)
|
|
114
|
+
const getValueString = (val: any): string => {
|
|
115
|
+
if (typeof val === 'string') return val
|
|
116
|
+
if (val?.number) return val.number
|
|
117
|
+
return ""
|
|
118
|
+
}
|
|
119
|
+
const [inputValue, setInputValue] = useState(getValueString(value))
|
|
114
120
|
const [error, setError] = useState(props.error || "")
|
|
115
121
|
const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
|
|
116
122
|
const [selectedData, setSelectedData] = useState()
|
|
@@ -119,6 +125,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
119
125
|
const [formSubmitted, setFormSubmitted] = useState(false)
|
|
120
126
|
const [hasStartedValidating, setHasStartedValidating] = useState(false)
|
|
121
127
|
|
|
128
|
+
// Sync value prop when it changes (e.g., from react-hook-form)
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const newValue = getValueString(props.value)
|
|
131
|
+
if (newValue !== inputValue) {
|
|
132
|
+
setInputValue(newValue)
|
|
133
|
+
}
|
|
134
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
135
|
+
}, [props.value])
|
|
136
|
+
|
|
122
137
|
// Only sync initial error from props, not continuous updates
|
|
123
138
|
// Once validation starts, internal validation takes over
|
|
124
139
|
useEffect(() => {
|
|
@@ -147,6 +162,10 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
147
162
|
// Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
|
|
148
163
|
const shouldShowInternalError = (hasBlurred || formSubmitted) && error
|
|
149
164
|
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 || "") : ""
|
|
150
169
|
|
|
151
170
|
useEffect(() => {
|
|
152
171
|
const hasError = (error ?? '').length > 0
|
|
@@ -493,12 +512,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
|
|
|
493
512
|
dark,
|
|
494
513
|
"data-phone-number": JSON.stringify(selectedData),
|
|
495
514
|
disabled,
|
|
496
|
-
error:
|
|
515
|
+
error: displayError || propError,
|
|
497
516
|
type: 'tel',
|
|
498
517
|
id,
|
|
499
518
|
label,
|
|
500
519
|
name,
|
|
501
|
-
onBlur: (
|
|
520
|
+
onBlur: () => {
|
|
502
521
|
setHasBlurred(true)
|
|
503
522
|
validateErrors()
|
|
504
523
|
},
|