aport-tools 4.4.28 → 4.4.29
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.
- package/dist/index.esm.js +33 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +32 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
/*! aport-tools v4.4.
|
2
|
-
import React, { useContext, useState,
|
1
|
+
/*! aport-tools v4.4.29 | ISC */
|
2
|
+
import React, { useContext, useState, useRef, createContext, useEffect, useMemo, useCallback } from 'react';
|
3
3
|
import { StyleSheet, Text as Text$1, Animated, View, TouchableOpacity, Image, TextInput, Modal, Pressable, FlatList, Keyboard, Platform, Alert, ActivityIndicator } from 'react-native';
|
4
4
|
import { ThemeContext } from 'aport-themes';
|
5
5
|
import * as ImagePicker from 'expo-image-picker';
|
@@ -395,42 +395,66 @@ var Form = function Form(_a) {
|
|
395
395
|
var _c = useState({}),
|
396
396
|
errors = _c[0],
|
397
397
|
setErrors = _c[1];
|
398
|
+
// Ref to store the initial form values (firstValue).
|
399
|
+
var initialFormValues = useRef({});
|
398
400
|
var setFormValue = function setFormValue(name, value) {
|
399
401
|
setFormValues(function (prev) {
|
400
402
|
var _a;
|
401
403
|
return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
|
402
404
|
});
|
405
|
+
if (!initialFormValues.current[name]) {
|
406
|
+
initialFormValues.current[name] = value; // Set the initial value once.
|
407
|
+
}
|
403
408
|
};
|
404
409
|
var handleSubmit = function handleSubmit() {
|
405
410
|
return __awaiter(void 0, void 0, void 0, function () {
|
406
|
-
var validationErrors;
|
411
|
+
var modifiedFields, validationErrors;
|
407
412
|
return __generator(this, function (_a) {
|
408
413
|
switch (_a.label) {
|
409
414
|
case 0:
|
410
|
-
|
415
|
+
modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
|
416
|
+
var currentField = formValues[key]; // currentField is FormField
|
417
|
+
var initialField = currentField.firstValue; // Get initial value
|
418
|
+
// Compare current value with initial value
|
419
|
+
if (currentField.value !== initialField) {
|
420
|
+
acc[key] = currentField.value; // Include only modified fields
|
421
|
+
}
|
422
|
+
return acc;
|
423
|
+
}, {});
|
424
|
+
return [4 /*yield*/, onSubmit(modifiedFields)];
|
411
425
|
case 1:
|
412
426
|
validationErrors = _a.sent();
|
413
427
|
// Set the validation errors in state
|
414
428
|
setErrors(validationErrors);
|
415
|
-
// Prevent submission if there are
|
429
|
+
// Prevent submission if there are validation errors
|
416
430
|
if (Object.keys(validationErrors).length > 0) {
|
417
|
-
return [2 /*return*/]; //
|
431
|
+
return [2 /*return*/]; // Exit early if errors are present
|
418
432
|
}
|
419
433
|
return [2 /*return*/];
|
420
434
|
}
|
421
435
|
});
|
422
436
|
});
|
423
437
|
};
|
424
|
-
var handleFormSubmit = function handleFormSubmit(
|
438
|
+
var handleFormSubmit = function handleFormSubmit() {
|
425
439
|
return __awaiter(void 0, void 0, void 0, function () {
|
426
|
-
var validationErrors;
|
440
|
+
var modifiedFields, validationErrors;
|
427
441
|
return __generator(this, function (_a) {
|
428
442
|
switch (_a.label) {
|
429
443
|
case 0:
|
430
|
-
|
444
|
+
modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
|
445
|
+
var currentField = formValues[key];
|
446
|
+
var initialField = currentField === null || currentField === void 0 ? void 0 : currentField.firstValue; // Get initial value
|
447
|
+
if (currentField.value !== initialField) {
|
448
|
+
acc[key] = currentField.value; // Include only modified fields
|
449
|
+
}
|
450
|
+
return acc;
|
451
|
+
}, {});
|
452
|
+
return [4 /*yield*/, onSubmit(modifiedFields)];
|
431
453
|
case 1:
|
432
454
|
validationErrors = _a.sent();
|
455
|
+
// Set the validation errors in state
|
433
456
|
setErrors(validationErrors);
|
457
|
+
// Return validation errors to allow further actions if needed
|
434
458
|
return [2 /*return*/, validationErrors];
|
435
459
|
}
|
436
460
|
});
|