aport-tools 4.4.29 → 4.4.30

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.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! aport-tools v4.4.29 | ISC */
1
+ /*! aport-tools v4.4.30 | ISC */
2
2
  'use strict';
3
3
 
4
4
  var React = require('react');
@@ -416,16 +416,11 @@ var Form = function Form(_a) {
416
416
  var _c = React.useState({}),
417
417
  errors = _c[0],
418
418
  setErrors = _c[1];
419
- // Ref to store the initial form values (firstValue).
420
- var initialFormValues = React.useRef({});
421
419
  var setFormValue = function setFormValue(name, value) {
422
420
  setFormValues(function (prev) {
423
421
  var _a;
424
422
  return __assign(__assign({}, prev), (_a = {}, _a[name] = value, _a));
425
423
  });
426
- if (!initialFormValues.current[name]) {
427
- initialFormValues.current[name] = value; // Set the initial value once.
428
- }
429
424
  };
430
425
  var handleSubmit = function handleSubmit() {
431
426
  return __awaiter(void 0, void 0, void 0, function () {
@@ -434,11 +429,16 @@ var Form = function Form(_a) {
434
429
  switch (_a.label) {
435
430
  case 0:
436
431
  modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
437
- var currentField = formValues[key]; // currentField is FormField
438
- var initialField = currentField.firstValue; // Get initial value
439
- // Compare current value with initial value
440
- if (currentField.value !== initialField) {
441
- acc[key] = currentField.value; // Include only modified fields
432
+ var currentField = formValues[key];
433
+ // Check if firstValue exists
434
+ if ((currentField === null || currentField === void 0 ? void 0 : currentField.firstValue) !== undefined) {
435
+ // Only include the field if the value has changed
436
+ if (currentField.value !== currentField.firstValue) {
437
+ acc[key] = currentField.value;
438
+ }
439
+ } else {
440
+ // Include the field if firstValue is not defined
441
+ acc[key] = currentField.value;
442
442
  }
443
443
  return acc;
444
444
  }, {});
@@ -456,26 +456,16 @@ var Form = function Form(_a) {
456
456
  });
457
457
  });
458
458
  };
459
- var handleFormSubmit = function handleFormSubmit() {
459
+ var handleFormSubmit = function handleFormSubmit(formValues) {
460
460
  return __awaiter(void 0, void 0, void 0, function () {
461
- var modifiedFields, validationErrors;
461
+ var validationErrors;
462
462
  return __generator(this, function (_a) {
463
463
  switch (_a.label) {
464
464
  case 0:
465
- modifiedFields = Object.keys(formValues).reduce(function (acc, key) {
466
- var currentField = formValues[key];
467
- var initialField = currentField === null || currentField === void 0 ? void 0 : currentField.firstValue; // Get initial value
468
- if (currentField.value !== initialField) {
469
- acc[key] = currentField.value; // Include only modified fields
470
- }
471
- return acc;
472
- }, {});
473
- return [4 /*yield*/, onSubmit(modifiedFields)];
465
+ return [4 /*yield*/, onSubmit(formValues)];
474
466
  case 1:
475
467
  validationErrors = _a.sent();
476
- // Set the validation errors in state
477
468
  setErrors(validationErrors);
478
- // Return validation errors to allow further actions if needed
479
469
  return [2 /*return*/, validationErrors];
480
470
  }
481
471
  });