@maro-tech/form 0.0.16 → 0.0.17

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.
@@ -8,7 +8,7 @@ import { FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
8
8
  import { Subject, debounceTime, distinctUntilChanged, forkJoin, map, Observable, from, switchMap, of } from 'rxjs';
9
9
  import { BrowserMultiFormatOneDReader } from '@zxing/browser';
10
10
  import { DecodeHintType, BarcodeFormat } from '@zxing/library';
11
- import { UiButtonComponent } from '@maro-tech/core';
11
+ import { UiButtonComponent, UiToastService } from '@maro-tech/core';
12
12
  import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
13
13
  import * as i1 from 'lucide-angular';
14
14
  import { X, ChevronDown, Check, LucideAngularModule, CalendarDays, ChevronLeft, ChevronRight, Eye, EyeOff } from 'lucide-angular';
@@ -2915,6 +2915,7 @@ class UiActionFormModalComponent {
2915
2915
  }), ...(ngDevMode ? [{ debugName: "panelClass" }] : /* istanbul ignore next */ []));
2916
2916
  http = inject(HttpClient);
2917
2917
  router = inject(Router);
2918
+ toast = inject(UiToastService);
2918
2919
  ngOnChanges(changes) {
2919
2920
  if (this.isOpen() && ('isOpen' in changes || 'formId' in changes || 'recordId' in changes)) {
2920
2921
  this.loadForm();
@@ -2962,6 +2963,13 @@ class UiActionFormModalComponent {
2962
2963
  if (!endpoint)
2963
2964
  return;
2964
2965
  const payload = this.normalizePayload({ ...(this.initialValue() || {}), ...(action?.payload || {}), ...this.formValue() });
2966
+ const missingFields = flattenDynamicFormFields(this.fields())
2967
+ .filter((field) => field.type !== 'container' && field.type !== 'template' && field.required && this.isEmptyValue(payload[field.id]))
2968
+ .map((field) => String(field.label || field.title || field.id));
2969
+ if (missingFields.length) {
2970
+ this.toast.show(`Заповніть обов’язкові поля: ${missingFields.join(', ')}`, 'warning', 4000);
2971
+ return;
2972
+ }
2965
2973
  const recordId = String(this.recordId() || '').trim();
2966
2974
  if (recordId && !Object.prototype.hasOwnProperty.call(payload, 'id'))
2967
2975
  payload['id'] = recordId;
@@ -2976,7 +2984,10 @@ class UiActionFormModalComponent {
2976
2984
  this.navigateAfterSubmit(response);
2977
2985
  this.close();
2978
2986
  },
2979
- error: () => this.isSubmitting.set(false),
2987
+ error: (error) => {
2988
+ this.isSubmitting.set(false);
2989
+ this.toast.show(error?.error?.message || 'Не вдалося відправити форму', 'error', 4000);
2990
+ },
2980
2991
  });
2981
2992
  }
2982
2993
  loadForm() {
@@ -3026,6 +3037,17 @@ class UiActionFormModalComponent {
3026
3037
  }
3027
3038
  return payload;
3028
3039
  }
3040
+ isEmptyValue(value) {
3041
+ if (value == null)
3042
+ return true;
3043
+ if (Array.isArray(value))
3044
+ return value.length === 0;
3045
+ if (typeof value === 'string')
3046
+ return value.trim() === '';
3047
+ if (typeof value === 'number')
3048
+ return !Number.isFinite(value);
3049
+ return false;
3050
+ }
3029
3051
  normalizeActionType(type) {
3030
3052
  const normalized = String(type || '').trim().toLowerCase();
3031
3053
  if (normalized === 'api' || normalized === 'action_api')