aport-tools 4.4.27 → 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/forms/InputCheck.d.ts +1 -1
- package/dist/index.esm.js +56 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +55 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
@@ -13,7 +13,7 @@ interface InputCheckProps {
|
|
13
13
|
rowAmount?: number;
|
14
14
|
iconPosition?: "row" | "column";
|
15
15
|
disabled?: boolean;
|
16
|
-
firstValue
|
16
|
+
firstValue?: InputOption[];
|
17
17
|
}
|
18
18
|
declare const InputCheck: React.FC<InputCheckProps>;
|
19
19
|
export default InputCheck;
|
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
|
});
|
@@ -1015,38 +1039,33 @@ var InputCheck = function InputCheck(_a) {
|
|
1015
1039
|
max = _a.max,
|
1016
1040
|
_c = _a.rowAmount,
|
1017
1041
|
rowAmount = _c === void 0 ? 3 : _c,
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
setSelectedValues = _h[1];
|
1042
|
+
firstValue = _a.firstValue,
|
1043
|
+
_d = _a.iconPosition,
|
1044
|
+
iconPosition = _d === void 0 ? "row" : _d,
|
1045
|
+
_e = _a.disabled,
|
1046
|
+
disabled = _e === void 0 ? false : _e;
|
1047
|
+
var _f = useFormContext();
|
1048
|
+
_f.formValues;
|
1049
|
+
var setFormValue = _f.setFormValue,
|
1050
|
+
formErrors = _f.errors;
|
1051
|
+
var _g = useState([]),
|
1052
|
+
selectedValues = _g[0],
|
1053
|
+
setSelectedValues = _g[1];
|
1031
1054
|
var theme = useContext(ThemeContext).theme;
|
1032
1055
|
var colors = theme.colors;
|
1033
|
-
|
1056
|
+
var isFirstRender = useRef(true);
|
1057
|
+
// Initialize selectedValues on first render if firstValue is provided
|
1034
1058
|
useEffect(function () {
|
1035
|
-
|
1036
|
-
|
1037
|
-
return
|
1059
|
+
if (isFirstRender.current && firstValue) {
|
1060
|
+
var initialSelectedValues = options.filter(function (option) {
|
1061
|
+
return firstValue.some(function (fv) {
|
1062
|
+
return fv.value === option.value;
|
1063
|
+
});
|
1038
1064
|
});
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
return {
|
1044
|
-
id: id,
|
1045
|
-
value: value
|
1046
|
-
};
|
1047
|
-
});
|
1048
|
-
setSelectedValues(formattedValues);
|
1049
|
-
setFormValue(name, formattedValues); // Update form context
|
1065
|
+
setSelectedValues(initialSelectedValues);
|
1066
|
+
setFormValue(name, initialSelectedValues); // Update form context
|
1067
|
+
isFirstRender.current = false; // Prevent subsequent updates
|
1068
|
+
}
|
1050
1069
|
}, [firstValue, name, options, setFormValue]);
|
1051
1070
|
var handleSelect = function handleSelect(id, value) {
|
1052
1071
|
if (disabled) return;
|