@iapps/ng-dhis2-ui 1.2.71 → 1.2.73

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.
@@ -4734,6 +4734,7 @@ class FormField {
4734
4734
  this.selectedOptionsLabel =
4735
4735
  options.availableOptionsLabel ?? 'Selected options';
4736
4736
  this.allowFutureDate = options.allowFutureDate;
4737
+ this.extension = options.extension;
4737
4738
  }
4738
4739
  setMax(field) {
4739
4740
  if (field.controlType !== 'date') {
@@ -5189,6 +5190,7 @@ class FormFieldGroup {
5189
5190
  const hasOptions = (options?.length > 0 ||
5190
5191
  dependentField !== undefined ||
5191
5192
  fieldMetaData['hasOptions']);
5193
+ const extension = this.params.formFieldExtensions?.find((fieldExtension) => fieldExtension?.id === field.id);
5192
5194
  return new FormField({
5193
5195
  ...(fieldMetaData || {}),
5194
5196
  ...field,
@@ -5216,6 +5218,7 @@ class FormFieldGroup {
5216
5218
  controlType: FieldUtil.getFieldControlType(fieldMetaData['valueType'], hasOptions),
5217
5219
  metaType: fieldMetaData['metaType'],
5218
5220
  stepId: fieldMetaData['stepId'],
5221
+ extension,
5219
5222
  });
5220
5223
  })
5221
5224
  .filter((field) => field);
@@ -5356,6 +5359,7 @@ class FormMetadataSection {
5356
5359
  formFieldGroup,
5357
5360
  fieldMetaData: [...this.attributes, ...this.dataElements],
5358
5361
  locale: this.params.locale,
5362
+ formFieldExtensions: this.params.formFieldExtensions,
5359
5363
  }).toJson();
5360
5364
  });
5361
5365
  }
@@ -5387,6 +5391,7 @@ class FormMetaData {
5387
5391
  section,
5388
5392
  program,
5389
5393
  locale: this.params.locale,
5394
+ formFieldExtensions: this.params.formFieldExtensions,
5390
5395
  }).toJson();
5391
5396
  })
5392
5397
  .filter((section) => section !== null);
@@ -5472,6 +5477,7 @@ class FormMetaData {
5472
5477
  program,
5473
5478
  locale: this.params.locale,
5474
5479
  excludeInheritedAttributes: this.params.excludeInheritedAttributes,
5480
+ formFieldExtensions: this.params.formFieldExtensions,
5475
5481
  }).toJson();
5476
5482
  });
5477
5483
  }
@@ -5502,6 +5508,7 @@ class FormMetaData {
5502
5508
  program,
5503
5509
  locale: this.params.locale,
5504
5510
  excludeInheritedAttributes: this.params.excludeInheritedAttributes,
5511
+ formFieldExtensions: this.params.formFieldExtensions,
5505
5512
  }).toJson();
5506
5513
  }
5507
5514
  #getReportingDateSection(program) {
@@ -5539,6 +5546,7 @@ class FormMetaData {
5539
5546
  program,
5540
5547
  locale: this.params.locale,
5541
5548
  excludeInheritedAttributes: this.params.excludeInheritedAttributes,
5549
+ formFieldExtensions: this.params.formFieldExtensions,
5542
5550
  }).toJson();
5543
5551
  }
5544
5552
  #getRegistrationSection(program) {
@@ -5572,6 +5580,7 @@ class FormMetaData {
5572
5580
  program,
5573
5581
  locale: this.params.locale,
5574
5582
  excludeInheritedAttributes: this.params.excludeInheritedAttributes,
5583
+ formFieldExtensions: this.params.formFieldExtensions,
5575
5584
  }).toJson();
5576
5585
  }
5577
5586
  #getMergedRegistrationSection(program) {
@@ -5648,6 +5657,7 @@ class FormMetaData {
5648
5657
  program,
5649
5658
  locale: this.params.locale,
5650
5659
  excludeInheritedAttributes: this.params.excludeInheritedAttributes,
5660
+ formFieldExtensions: this.params.formFieldExtensions,
5651
5661
  }).toJson();
5652
5662
  }
5653
5663
  toJson() {
@@ -5700,10 +5710,11 @@ class FormValue {
5700
5710
  // Use of this source code is governed by a BSD-style
5701
5711
  // license that can be found in the LICENSE file.
5702
5712
  const FileUploadField = (props) => {
5703
- const { label, id, uploadUrl, performUpload, validationText, required, hasError, onChange, onUploadSuccess, } = props;
5713
+ const { label, id, uploadUrl, performUpload, validationText, required, hasError, onChange, onUploadSuccess, extension } = props;
5704
5714
  const d2 = window?.d2Web;
5705
5715
  const [file, setFile] = useState(null);
5706
5716
  const [uploading, setUploading] = useState();
5717
+ const [validationError, setValidationError] = useState(null);
5707
5718
  const valid = useMemo(() => {
5708
5719
  if (isUndefined(hasError)) {
5709
5720
  return undefined;
@@ -5729,8 +5740,14 @@ const FileUploadField = (props) => {
5729
5740
  }
5730
5741
  }
5731
5742
  };
5732
- return (React__default.createElement(FileInputField, { accept: "*", buttonLabel: "Upload a file", label: label, name: id, required: required, validationText: validationText, onChange: (event) => {
5743
+ return (React__default.createElement(FileInputField, { accept: extension?.accept?.join(','), buttonLabel: "Upload a file", label: label, name: id, required: required, error: !!validationError, validationText: validationError || validationText, onChange: (event) => {
5733
5744
  const fileItem = (event?.files || [])[0];
5745
+ setValidationError(null);
5746
+ if (extension?.sizeLimit && fileItem.size > extension?.sizeLimit) {
5747
+ setValidationError(`File size must not exceed ${extension.sizeLimit / (1024 * 1024)}MB`);
5748
+ setFile(null);
5749
+ return;
5750
+ }
5734
5751
  setFile(fileItem);
5735
5752
  if (performUpload) {
5736
5753
  uploadFile(fileItem);
@@ -6157,7 +6174,7 @@ class BaseFormFieldComponent extends ReactWrapperModule {
6157
6174
  });
6158
6175
  setValue(fileId);
6159
6176
  setTouched(true);
6160
- } })));
6177
+ }, extension: this.field()?.extension })));
6161
6178
  default:
6162
6179
  return (React__default.createElement(InputField$1, { error: hasError, validationText: validationError, type: this.field().type, inputWidth: this.fieldConfig()?.inputWidth, required: this.field().required, name: this.field().id, label: this.label(), min: this.field().min?.toString(), max: this.field().max?.toString(), placeholder: this.placeholder(), value: value, readOnly: disabled, onChange: (event) => {
6163
6180
  this.ngZone.run(() => {
@@ -7241,7 +7258,6 @@ class TrackerFormComponent {
7241
7258
  }
7242
7259
  onFormUpdate(values) {
7243
7260
  const instance = this.instance;
7244
- console.log(instance);
7245
7261
  instance?.updateDataValues(values);
7246
7262
  }
7247
7263
  onSave(event) { }
@@ -7467,6 +7483,7 @@ class ProgramEntryFormFieldUtil {
7467
7483
  .map((field) => {
7468
7484
  const options = FieldDropdown.getDropdownOptions(field);
7469
7485
  const hasOptions = options?.length > 0;
7486
+ const extension = this.config.formFieldExtensions?.find((fieldExtension) => fieldExtension?.id === field.id);
7470
7487
  return new FormField({
7471
7488
  ...field,
7472
7489
  id: field.id,
@@ -7482,6 +7499,7 @@ class ProgramEntryFormFieldUtil {
7482
7499
  controlType: FieldUtil.getFieldControlType(field.valueType, hasOptions),
7483
7500
  metaType: field.metaType,
7484
7501
  stepId: field.stepId,
7502
+ extension,
7485
7503
  });
7486
7504
  })
7487
7505
  .sort((a, b) => a.order ?? 0 - (b.order ?? 0));