@tagadapay/plugin-sdk 1.0.13 → 1.0.15
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,19 +308,16 @@ 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) {
|
|
315
318
|
setIsAddressSelected(false);
|
|
316
319
|
}
|
|
317
|
-
|
|
318
|
-
// This ensures that manual typing (without Google Places selection) is saved
|
|
319
|
-
triggerAutoSave('manual');
|
|
320
|
-
}, [isAddressSelected, triggerAutoSave]);
|
|
320
|
+
}, [isAddressSelected]);
|
|
321
321
|
// Sync addressInputValue with external changes
|
|
322
322
|
useEffect(() => {
|
|
323
323
|
const currentAddress = fields.address1.value;
|
|
@@ -338,13 +338,16 @@ export function useAddress(options = {}) {
|
|
|
338
338
|
// Form methods
|
|
339
339
|
const setValue = useCallback((field, value) => {
|
|
340
340
|
setFields((prev) => {
|
|
341
|
-
|
|
341
|
+
// Only show validation errors for touched fields when autoValidate is enabled
|
|
342
|
+
const shouldValidate = autoValidate && prev[field].touched;
|
|
343
|
+
const error = shouldValidate ? validationRules[field]?.(value) : undefined;
|
|
342
344
|
const newFields = {
|
|
343
345
|
...prev,
|
|
344
346
|
[field]: {
|
|
345
347
|
value,
|
|
346
348
|
isValid: !error,
|
|
347
349
|
error,
|
|
350
|
+
touched: true, // Mark field as touched when user interacts with it
|
|
348
351
|
},
|
|
349
352
|
};
|
|
350
353
|
return newFields;
|
|
@@ -357,7 +360,7 @@ export function useAddress(options = {}) {
|
|
|
357
360
|
if (field === 'country') {
|
|
358
361
|
setFields((prev) => ({
|
|
359
362
|
...prev,
|
|
360
|
-
state: { ...prev.state, value: '', error: undefined, isValid: true },
|
|
363
|
+
state: { ...prev.state, value: '', error: undefined, isValid: true, touched: false },
|
|
361
364
|
}));
|
|
362
365
|
}
|
|
363
366
|
// Trigger auto-save after field update with longer debounce for manual typing
|
|
@@ -368,11 +371,15 @@ export function useAddress(options = {}) {
|
|
|
368
371
|
const newFields = { ...prev };
|
|
369
372
|
Object.entries(values).forEach(([key, value]) => {
|
|
370
373
|
const field = key;
|
|
371
|
-
|
|
374
|
+
// Only validate if field was previously touched or if we're setting a non-empty value
|
|
375
|
+
const hasNonEmptyValue = value && value.trim() !== '';
|
|
376
|
+
const shouldValidate = autoValidate && (prev[field].touched || hasNonEmptyValue);
|
|
377
|
+
const error = shouldValidate ? validationRules[field]?.(value || '') : undefined;
|
|
372
378
|
newFields[field] = {
|
|
373
379
|
value: value || '',
|
|
374
380
|
isValid: !error,
|
|
375
381
|
error,
|
|
382
|
+
touched: prev[field].touched || !!hasNonEmptyValue, // Mark as touched if setting a non-empty value
|
|
376
383
|
};
|
|
377
384
|
});
|
|
378
385
|
return newFields;
|
|
@@ -385,6 +392,7 @@ export function useAddress(options = {}) {
|
|
|
385
392
|
value: '',
|
|
386
393
|
isValid: true,
|
|
387
394
|
error: undefined,
|
|
395
|
+
touched: false,
|
|
388
396
|
},
|
|
389
397
|
}));
|
|
390
398
|
}, []);
|
|
@@ -407,6 +415,7 @@ export function useAddress(options = {}) {
|
|
|
407
415
|
value: '',
|
|
408
416
|
isValid: true,
|
|
409
417
|
error: undefined,
|
|
418
|
+
touched: false,
|
|
410
419
|
};
|
|
411
420
|
});
|
|
412
421
|
setFields(resetFields);
|
|
@@ -420,7 +429,12 @@ export function useAddress(options = {}) {
|
|
|
420
429
|
const error = rule ? rule(value) : undefined;
|
|
421
430
|
setFields((prev) => ({
|
|
422
431
|
...prev,
|
|
423
|
-
[fieldName]: {
|
|
432
|
+
[fieldName]: {
|
|
433
|
+
...prev[fieldName],
|
|
434
|
+
isValid: !error,
|
|
435
|
+
error,
|
|
436
|
+
touched: true, // Mark as touched when explicitly validating
|
|
437
|
+
},
|
|
424
438
|
}));
|
|
425
439
|
return !error;
|
|
426
440
|
}, [fields, validationRules]);
|
|
@@ -447,7 +461,12 @@ export function useAddress(options = {}) {
|
|
|
447
461
|
if (field === 'state' &&
|
|
448
462
|
fields.country.value &&
|
|
449
463
|
COUNTRIES_WITHOUT_STATE_FIELD.includes(fields.country.value)) {
|
|
450
|
-
newFields[field] = {
|
|
464
|
+
newFields[field] = {
|
|
465
|
+
...newFields[field],
|
|
466
|
+
isValid: true,
|
|
467
|
+
error: undefined,
|
|
468
|
+
touched: true,
|
|
469
|
+
};
|
|
451
470
|
return;
|
|
452
471
|
}
|
|
453
472
|
const error = validationRules[field]?.(value);
|
|
@@ -455,6 +474,7 @@ export function useAddress(options = {}) {
|
|
|
455
474
|
...newFields[field],
|
|
456
475
|
isValid: !error,
|
|
457
476
|
error,
|
|
477
|
+
touched: true, // Mark all fields as touched when validating all
|
|
458
478
|
};
|
|
459
479
|
if (error)
|
|
460
480
|
isValid = false;
|