@tagadapay/plugin-sdk 1.0.13 → 1.0.14
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.
|
@@ -71,10 +71,12 @@ export function useAddress(options = {}) {
|
|
|
71
71
|
];
|
|
72
72
|
fieldNames.forEach((field) => {
|
|
73
73
|
const value = initialValues[field] || '';
|
|
74
|
+
// Don't show errors on initial load, even with autoValidate
|
|
74
75
|
initialFields[field] = {
|
|
75
76
|
value,
|
|
76
|
-
isValid:
|
|
77
|
-
error:
|
|
77
|
+
isValid: true, // Start as valid to avoid showing errors on first load
|
|
78
|
+
error: undefined, // No errors on initial load
|
|
79
|
+
touched: false, // Mark as untouched initially
|
|
78
80
|
};
|
|
79
81
|
});
|
|
80
82
|
return initialFields;
|
|
@@ -204,6 +206,7 @@ export function useAddress(options = {}) {
|
|
|
204
206
|
value,
|
|
205
207
|
isValid: !error,
|
|
206
208
|
error,
|
|
209
|
+
touched: true, // Mark as touched when Google Places fills the field
|
|
207
210
|
};
|
|
208
211
|
};
|
|
209
212
|
console.log('🔄 Updating fields from Google Places:', {
|
|
@@ -305,10 +308,10 @@ export function useAddress(options = {}) {
|
|
|
305
308
|
const value = event.target.value;
|
|
306
309
|
// Update local state immediately for responsive UI
|
|
307
310
|
setAddressInputValue(value);
|
|
308
|
-
// Update form field immediately (no debounce)
|
|
311
|
+
// Update form field immediately (no debounce) and mark as touched
|
|
309
312
|
setFields((prev) => ({
|
|
310
313
|
...prev,
|
|
311
|
-
address1: { ...prev.address1, value },
|
|
314
|
+
address1: { ...prev.address1, value, touched: true },
|
|
312
315
|
}));
|
|
313
316
|
// Reset address selection flag when user types manually
|
|
314
317
|
if (isAddressSelected) {
|
|
@@ -338,13 +341,16 @@ export function useAddress(options = {}) {
|
|
|
338
341
|
// Form methods
|
|
339
342
|
const setValue = useCallback((field, value) => {
|
|
340
343
|
setFields((prev) => {
|
|
341
|
-
|
|
344
|
+
// Only show validation errors for touched fields when autoValidate is enabled
|
|
345
|
+
const shouldValidate = autoValidate && prev[field].touched;
|
|
346
|
+
const error = shouldValidate ? validationRules[field]?.(value) : undefined;
|
|
342
347
|
const newFields = {
|
|
343
348
|
...prev,
|
|
344
349
|
[field]: {
|
|
345
350
|
value,
|
|
346
351
|
isValid: !error,
|
|
347
352
|
error,
|
|
353
|
+
touched: true, // Mark field as touched when user interacts with it
|
|
348
354
|
},
|
|
349
355
|
};
|
|
350
356
|
return newFields;
|
|
@@ -357,7 +363,7 @@ export function useAddress(options = {}) {
|
|
|
357
363
|
if (field === 'country') {
|
|
358
364
|
setFields((prev) => ({
|
|
359
365
|
...prev,
|
|
360
|
-
state: { ...prev.state, value: '', error: undefined, isValid: true },
|
|
366
|
+
state: { ...prev.state, value: '', error: undefined, isValid: true, touched: false },
|
|
361
367
|
}));
|
|
362
368
|
}
|
|
363
369
|
// Trigger auto-save after field update with longer debounce for manual typing
|
|
@@ -368,11 +374,15 @@ export function useAddress(options = {}) {
|
|
|
368
374
|
const newFields = { ...prev };
|
|
369
375
|
Object.entries(values).forEach(([key, value]) => {
|
|
370
376
|
const field = key;
|
|
371
|
-
|
|
377
|
+
// Only validate if field was previously touched or if we're setting a non-empty value
|
|
378
|
+
const hasNonEmptyValue = value && value.trim() !== '';
|
|
379
|
+
const shouldValidate = autoValidate && (prev[field].touched || hasNonEmptyValue);
|
|
380
|
+
const error = shouldValidate ? validationRules[field]?.(value || '') : undefined;
|
|
372
381
|
newFields[field] = {
|
|
373
382
|
value: value || '',
|
|
374
383
|
isValid: !error,
|
|
375
384
|
error,
|
|
385
|
+
touched: prev[field].touched || !!hasNonEmptyValue, // Mark as touched if setting a non-empty value
|
|
376
386
|
};
|
|
377
387
|
});
|
|
378
388
|
return newFields;
|
|
@@ -385,6 +395,7 @@ export function useAddress(options = {}) {
|
|
|
385
395
|
value: '',
|
|
386
396
|
isValid: true,
|
|
387
397
|
error: undefined,
|
|
398
|
+
touched: false,
|
|
388
399
|
},
|
|
389
400
|
}));
|
|
390
401
|
}, []);
|
|
@@ -407,6 +418,7 @@ export function useAddress(options = {}) {
|
|
|
407
418
|
value: '',
|
|
408
419
|
isValid: true,
|
|
409
420
|
error: undefined,
|
|
421
|
+
touched: false,
|
|
410
422
|
};
|
|
411
423
|
});
|
|
412
424
|
setFields(resetFields);
|
|
@@ -420,7 +432,12 @@ export function useAddress(options = {}) {
|
|
|
420
432
|
const error = rule ? rule(value) : undefined;
|
|
421
433
|
setFields((prev) => ({
|
|
422
434
|
...prev,
|
|
423
|
-
[fieldName]: {
|
|
435
|
+
[fieldName]: {
|
|
436
|
+
...prev[fieldName],
|
|
437
|
+
isValid: !error,
|
|
438
|
+
error,
|
|
439
|
+
touched: true, // Mark as touched when explicitly validating
|
|
440
|
+
},
|
|
424
441
|
}));
|
|
425
442
|
return !error;
|
|
426
443
|
}, [fields, validationRules]);
|
|
@@ -447,7 +464,12 @@ export function useAddress(options = {}) {
|
|
|
447
464
|
if (field === 'state' &&
|
|
448
465
|
fields.country.value &&
|
|
449
466
|
COUNTRIES_WITHOUT_STATE_FIELD.includes(fields.country.value)) {
|
|
450
|
-
newFields[field] = {
|
|
467
|
+
newFields[field] = {
|
|
468
|
+
...newFields[field],
|
|
469
|
+
isValid: true,
|
|
470
|
+
error: undefined,
|
|
471
|
+
touched: true,
|
|
472
|
+
};
|
|
451
473
|
return;
|
|
452
474
|
}
|
|
453
475
|
const error = validationRules[field]?.(value);
|
|
@@ -455,6 +477,7 @@ export function useAddress(options = {}) {
|
|
|
455
477
|
...newFields[field],
|
|
456
478
|
isValid: !error,
|
|
457
479
|
error,
|
|
480
|
+
touched: true, // Mark all fields as touched when validating all
|
|
458
481
|
};
|
|
459
482
|
if (error)
|
|
460
483
|
isValid = false;
|