@ldquocc/dynamic-form 0.0.8 → 0.0.9
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/ng-package.json +15 -0
- package/package.json +20 -31
- package/src/lib/dynamic-form.component.html +121 -0
- package/src/lib/dynamic-form.component.scss +7 -0
- package/src/lib/dynamic-form.component.spec.ts +21 -0
- package/src/lib/dynamic-form.component.ts +237 -0
- package/src/lib/dynamic-form.service.spec.ts +16 -0
- package/src/lib/dynamic-form.service.ts +9 -0
- package/src/lib/shared/base/base-select.component.ts +183 -0
- package/src/lib/shared/base/base-value-accessor.ts +192 -0
- package/{lib/shared/components/component.d.ts → src/lib/shared/components/component.ts} +34 -14
- package/src/lib/shared/components/d-form-testing/d-form-testing.component.html +197 -0
- package/src/lib/shared/components/d-form-testing/d-form-testing.component.less +12 -0
- package/src/lib/shared/components/d-form-testing/d-form-testing.component.spec.ts +22 -0
- package/src/lib/shared/components/d-form-testing/d-form-testing.component.ts +197 -0
- package/src/lib/shared/components/dynamic-field/dynamic-field.component.html +218 -0
- package/src/lib/shared/components/dynamic-field/dynamic-field.component.scss +28 -0
- package/src/lib/shared/components/dynamic-field/dynamic-field.component.spec.ts +21 -0
- package/src/lib/shared/components/dynamic-field/dynamic-field.component.ts +67 -0
- package/src/lib/shared/components/field-user-config/field-user-config.component.html +38 -0
- package/src/lib/shared/components/field-user-config/field-user-config.component.scss +29 -0
- package/src/lib/shared/components/field-user-config/field-user-config.component.ts +33 -0
- package/src/lib/shared/components/fields/components/suffix/suffix.component.html +42 -0
- package/src/lib/shared/components/fields/components/suffix/suffix.component.scss +3 -0
- package/src/lib/shared/components/fields/components/suffix/suffix.component.spec.ts +22 -0
- package/src/lib/shared/components/fields/components/suffix/suffix.component.ts +32 -0
- package/src/lib/shared/components/fields/date/date-picker/date-picker.component.html +20 -0
- package/src/lib/shared/components/fields/date/date-picker/date-picker.component.scss +5 -0
- package/src/lib/shared/components/fields/date/date-picker/date-picker.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/date/date-picker/date-picker.component.ts +148 -0
- package/src/lib/shared/components/fields/date/date-range/date-range.component.html +33 -0
- package/src/lib/shared/components/fields/date/date-range/date-range.component.scss +22 -0
- package/src/lib/shared/components/fields/date/date-range/date-range.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/date/date-range/date-range.component.ts +133 -0
- package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.html +31 -0
- package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.scss +3 -0
- package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.ts +148 -0
- package/src/lib/shared/components/fields/input/input-password/input-password.component.html +18 -0
- package/src/lib/shared/components/fields/input/input-password/input-password.component.scss +0 -0
- package/src/lib/shared/components/fields/input/input-password/input-password.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/input/input-password/input-password.component.ts +56 -0
- package/src/lib/shared/components/fields/input/input-text/input-text.component.html +73 -0
- package/src/lib/shared/components/fields/input/input-text/input-text.component.scss +0 -0
- package/src/lib/shared/components/fields/input/input-text/input-text.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/input/input-text/input-text.component.ts +98 -0
- package/src/lib/shared/components/fields/select/multi-select/multi-select.component.html +73 -0
- package/src/lib/shared/components/fields/select/multi-select/multi-select.component.scss +21 -0
- package/src/lib/shared/components/fields/select/multi-select/multi-select.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/select/multi-select/multi-select.component.ts +212 -0
- package/src/lib/shared/components/fields/select/single-select/single-select.component.html +55 -0
- package/src/lib/shared/components/fields/select/single-select/single-select.component.scss +1 -0
- package/src/lib/shared/components/fields/select/single-select/single-select.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/select/single-select/single-select.component.ts +217 -0
- package/src/lib/shared/components/fields/select/single-select/sl.component.old.txt +337 -0
- package/src/lib/shared/components/fields/select/single-select/sl.component.old2.txt +340 -0
- package/src/lib/shared/components/fields/select/tree-select/tree-select.component.html +38 -0
- package/src/lib/shared/components/fields/select/tree-select/tree-select.component.scss +1 -0
- package/src/lib/shared/components/fields/select/tree-select/tree-select.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/select/tree-select/tree-select.component.ts +401 -0
- package/src/lib/shared/components/fields/textarea/textarea.component.html +29 -0
- package/src/lib/shared/components/fields/textarea/textarea.component.scss +17 -0
- package/src/lib/shared/components/fields/textarea/textarea.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/textarea/textarea.component.ts +76 -0
- package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.html +30 -0
- package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.scss +22 -0
- package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.spec.ts +22 -0
- package/src/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.ts +217 -0
- package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.html +101 -0
- package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.scss +117 -0
- package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.spec.ts +22 -0
- package/src/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.ts +480 -0
- package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.html +82 -0
- package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.less +80 -0
- package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.spec.ts +22 -0
- package/src/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.ts +288 -0
- package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.html +104 -0
- package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.scss +37 -0
- package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.spec.ts +21 -0
- package/src/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.ts +317 -0
- package/src/lib/shared/config/dynamic-form.config.ts +11 -0
- package/src/lib/shared/consts/common/common.const.ts +5 -0
- package/src/lib/shared/consts/common/field-dependency.const.ts +1 -0
- package/src/lib/shared/consts/common/file.const.ts +130 -0
- package/{lib/shared/consts/common/index.d.ts → src/lib/shared/consts/common/index.ts} +4 -4
- package/src/lib/shared/consts/common/sample-test.const.ts +1648 -0
- package/src/lib/shared/consts/common/standalone-import.const.ts +51 -0
- package/src/lib/shared/consts/controls/control.const.ts +11 -0
- package/{lib/shared/consts/controls/index.d.ts → src/lib/shared/consts/controls/index.ts} +1 -1
- package/src/lib/shared/consts/fields/date-field.const.ts +12 -0
- package/src/lib/shared/consts/fields/field.const.ts +23 -0
- package/{lib/shared/consts/fields/index.d.ts → src/lib/shared/consts/fields/index.ts} +5 -5
- package/src/lib/shared/consts/fields/input-field.const.ts +4 -0
- package/src/lib/shared/consts/fields/input-formatted-field.const.ts +35 -0
- package/src/lib/shared/consts/fields/radio-field.const.ts +31 -0
- package/src/lib/shared/consts/fields/select-field.const.ts +7 -0
- package/src/lib/shared/consts/fields/upload-field.const.ts +1 -0
- package/src/lib/shared/consts/validators/index.ts +0 -0
- package/src/lib/shared/consts/validators/pattern.const.ts +117 -0
- package/src/lib/shared/enums/common/component-ui.enum.ts +8 -0
- package/src/lib/shared/enums/common/field-dependency.enum.ts +10 -0
- package/src/lib/shared/enums/common/file-size-type.enum.ts +6 -0
- package/{lib/shared/enums/common/index.d.ts → src/lib/shared/enums/common/index.ts} +4 -4
- package/src/lib/shared/enums/common/output-value-type.enum.ts +22 -0
- package/src/lib/shared/enums/common/view-mode.enum.ts +4 -0
- package/src/lib/shared/enums/controls/control.enum.ts +12 -0
- package/{lib/shared/enums/controls/index.d.ts → src/lib/shared/enums/controls/index.ts} +1 -1
- package/src/lib/shared/enums/fields/date-field.enum.ts +4 -0
- package/src/lib/shared/enums/fields/field.enum.ts +21 -0
- package/{lib/shared/enums/fields/index.d.ts → src/lib/shared/enums/fields/index.ts} +6 -6
- package/src/lib/shared/enums/fields/input-field.enum.ts +6 -0
- package/src/lib/shared/enums/fields/input-formatted-field.enum.ts +6 -0
- package/src/lib/shared/enums/fields/select-field.enum.ts +4 -0
- package/src/lib/shared/enums/fields/upload-field.enum.ts +5 -0
- package/src/lib/shared/enums/form/dynamic-form.enum.ts +6 -0
- package/{lib/shared/enums/form/index.d.ts → src/lib/shared/enums/form/index.ts} +1 -1
- package/{lib/shared/enums/validators/index.d.ts → src/lib/shared/enums/validators/index.ts} +2 -2
- package/src/lib/shared/enums/validators/regex.enum.ts +47 -0
- package/src/lib/shared/enums/validators/validators.enum.ts +17 -0
- package/src/lib/shared/factories/auto-numeric-options.factory.ts +14 -0
- package/src/lib/shared/models/common/api-config.model.ts +7 -0
- package/src/lib/shared/models/common/api-response.model.ts +20 -0
- package/src/lib/shared/models/common/common.model.ts +39 -0
- package/src/lib/shared/models/common/field-dependency.model.ts +27 -0
- package/src/lib/shared/models/common/file-config.model.ts +22 -0
- package/{lib/shared/models/common/index.d.ts → src/lib/shared/models/common/index.ts} +7 -7
- package/src/lib/shared/models/common/obj-field.model.ts +68 -0
- package/src/lib/shared/models/common/object-storage.model.ts +15 -0
- package/{lib/shared/models/common/output-value-type.model.d.ts → src/lib/shared/models/common/output-value-type.model.ts} +4 -4
- package/src/lib/shared/models/common/table-models.ts +16 -0
- package/{lib/shared/models/common/view-mode.model.d.ts → src/lib/shared/models/common/view-mode.model.ts} +1 -1
- package/{lib/shared/models/controls/control.model.d.ts → src/lib/shared/models/controls/control.model.ts} +3 -2
- package/{lib/shared/models/controls/index.d.ts → src/lib/shared/models/controls/index.ts} +1 -1
- package/src/lib/shared/models/fields/date/base-date-field.model.ts +52 -0
- package/src/lib/shared/models/fields/date/date-picker-field.model.ts +43 -0
- package/src/lib/shared/models/fields/date/date-range-field.model.ts +52 -0
- package/{lib/shared/models/fields/date/index.d.ts → src/lib/shared/models/fields/date/index.ts} +3 -3
- package/src/lib/shared/models/fields/field-grid.model.ts +10 -0
- package/src/lib/shared/models/fields/field-group.model.ts +50 -0
- package/src/lib/shared/models/fields/field-user-config.model.ts +8 -0
- package/src/lib/shared/models/fields/field.model.ts +184 -0
- package/{lib/shared/models/fields/index.d.ts → src/lib/shared/models/fields/index.ts} +2 -2
- package/{lib/shared/models/fields/input/index.d.ts → src/lib/shared/models/fields/input/index.ts} +4 -4
- package/src/lib/shared/models/fields/input/input-field.model.ts +111 -0
- package/src/lib/shared/models/fields/input/input-formatted-field.model.ts +38 -0
- package/src/lib/shared/models/fields/input/input-password-field.model.ts +38 -0
- package/src/lib/shared/models/fields/input/input-text-field.model.ts +26 -0
- package/src/lib/shared/models/fields/radio/index.ts +0 -0
- package/src/lib/shared/models/fields/radio/radio-base-field.model.ts +84 -0
- package/src/lib/shared/models/fields/select/index.ts +0 -0
- package/src/lib/shared/models/fields/select/multi-select-field.model.ts +46 -0
- package/src/lib/shared/models/fields/select/select-base-field.model.ts +125 -0
- package/src/lib/shared/models/fields/select/single-select-field.model.ts +43 -0
- package/src/lib/shared/models/fields/select/tree-select-field.model.ts +44 -0
- package/src/lib/shared/models/fields/textarea/index.ts +0 -0
- package/src/lib/shared/models/fields/textarea/textarea-field.model.ts +97 -0
- package/src/lib/shared/models/fields/upload/avatar-upload-field.model.ts +33 -0
- package/src/lib/shared/models/fields/upload/base-upload-field.model.ts +105 -0
- package/{lib/shared/models/fields/upload/index.d.ts → src/lib/shared/models/fields/upload/index.ts} +5 -5
- package/src/lib/shared/models/fields/upload/multi-file-upload-field.model.ts +34 -0
- package/src/lib/shared/models/fields/upload/multi-image-upload-field.model.ts +42 -0
- package/src/lib/shared/models/fields/upload/single-file-upload-field.model.ts +33 -0
- package/{lib/shared/models/form/dynamic-form.model.d.ts → src/lib/shared/models/form/dynamic-form.model.ts} +1 -1
- package/{lib/shared/models/form/index.d.ts → src/lib/shared/models/form/index.ts} +1 -1
- package/src/lib/shared/models/validations/index.ts +1 -0
- package/src/lib/shared/models/validations/validations.model.ts +14 -0
- package/src/lib/shared/services/dynamic-form.service.spec.ts +16 -0
- package/src/lib/shared/services/dynamic-form.service.ts +251 -0
- package/src/lib/shared/services/field.service.spec.ts +16 -0
- package/src/lib/shared/services/field.service.ts +152 -0
- package/src/lib/shared/services/file.service.spec.ts +16 -0
- package/src/lib/shared/services/file.service.ts +53 -0
- package/src/lib/shared/services/form-config.service.ts +53 -0
- package/src/lib/shared/services/form-data.service.spec.ts +16 -0
- package/src/lib/shared/services/form-data.service.ts +114 -0
- package/src/lib/shared/services/form-utils.ts +52 -0
- package/src/lib/shared/services/suffix.service.spec.ts +16 -0
- package/src/lib/shared/services/suffix.service.ts +16 -0
- package/src/lib/shared/services/validation.service.spec.ts +16 -0
- package/src/lib/shared/services/validation.service.ts +38 -0
- package/src/lib/shared/utils/common/common.utils.ts +52 -0
- package/{lib/shared/utils/common/index.d.ts → src/lib/shared/utils/common/index.ts} +1 -1
- package/src/lib/shared/utils/date/date.utils.ts +129 -0
- package/{lib/shared/utils/date/index.d.ts → src/lib/shared/utils/date/index.ts} +1 -1
- package/src/lib/shared/utils/dynamic-field/dynamic-field.ts +0 -0
- package/src/lib/shared/utils/dynamic-field/index.ts +0 -0
- package/src/lib/shared/utils/dynamic-form/dynamic-form.ts +114 -0
- package/src/lib/shared/utils/dynamic-form/index.ts +0 -0
- package/src/lib/shared/utils/fields/fields.ts +78 -0
- package/{lib/shared/utils/fields/index.d.ts → src/lib/shared/utils/fields/index.ts} +1 -1
- package/src/lib/shared/utils/file/file.utils.ts +37 -0
- package/{lib/shared/utils/file/index.d.ts → src/lib/shared/utils/file/index.ts} +1 -1
- package/src/lib/shared/utils/validators/custom-validators.ts +158 -0
- package/src/lib/shared/utils/validators/default-error-message.ts +42 -0
- package/{lib/shared/utils/validators/index.d.ts → src/lib/shared/utils/validators/index.ts} +3 -3
- package/src/lib/shared/utils/validators/pattern.ts +26 -0
- package/{public-api.d.ts → src/public-api.ts} +68 -28
- package/tsconfig.lib.json +15 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +15 -0
- package/fesm2022/ldquocc-dynamic-form.mjs +0 -4938
- package/fesm2022/ldquocc-dynamic-form.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/dynamic-form.component.d.ts +0 -67
- package/lib/shared/base/base-select.component.d.ts +0 -19
- package/lib/shared/base/base-value-accessor.d.ts +0 -69
- package/lib/shared/components/dynamic-field/dynamic-field.component.d.ts +0 -23
- package/lib/shared/components/field-user-config/field-user-config.component.d.ts +0 -10
- package/lib/shared/components/fields/components/suffix/suffix.component.d.ts +0 -12
- package/lib/shared/components/fields/date/date-picker/date-picker.component.d.ts +0 -17
- package/lib/shared/components/fields/date/date-range/date-range.component.d.ts +0 -17
- package/lib/shared/components/fields/input/input-formatted/input-formatted.component.d.ts +0 -20
- package/lib/shared/components/fields/input/input-password/input-password.component.d.ts +0 -12
- package/lib/shared/components/fields/input/input-text/input-text.component.d.ts +0 -14
- package/lib/shared/components/fields/select/multi-select/multi-select.component.d.ts +0 -21
- package/lib/shared/components/fields/select/single-select/single-select.component.d.ts +0 -21
- package/lib/shared/components/fields/select/tree-select/tree-select.component.d.ts +0 -28
- package/lib/shared/components/fields/textarea/textarea.component.d.ts +0 -14
- package/lib/shared/components/fields/upload/avatar-upload/avatar-upload.component.d.ts +0 -25
- package/lib/shared/components/fields/upload/multi-file-upload/multi-file-upload.component.d.ts +0 -76
- package/lib/shared/components/fields/upload/multi-image-upload/multi-image-upload.component.d.ts +0 -27
- package/lib/shared/components/fields/upload/single-file-upload/single-file-upload.component.d.ts +0 -29
- package/lib/shared/config/dynamic-form.config.d.ts +0 -9
- package/lib/shared/consts/common/common.const.d.ts +0 -5
- package/lib/shared/consts/common/field-dependency.const.d.ts +0 -1
- package/lib/shared/consts/common/file.const.d.ts +0 -148
- package/lib/shared/consts/common/standalone-import.const.d.ts +0 -7
- package/lib/shared/consts/controls/control.const.d.ts +0 -1
- package/lib/shared/consts/fields/date-field.const.d.ts +0 -7
- package/lib/shared/consts/fields/field.const.d.ts +0 -4
- package/lib/shared/consts/fields/input-field.const.d.ts +0 -4
- package/lib/shared/consts/fields/input-formatted-field.const.d.ts +0 -4
- package/lib/shared/consts/fields/radio-field.const.d.ts +0 -10
- package/lib/shared/consts/fields/select-field.const.d.ts +0 -6
- package/lib/shared/consts/fields/upload-field.const.d.ts +0 -1
- package/lib/shared/consts/validators/pattern.const.d.ts +0 -2
- package/lib/shared/enums/common/field-dependency.enum.d.ts +0 -9
- package/lib/shared/enums/common/file-size-type.enum.d.ts +0 -6
- package/lib/shared/enums/common/output-value-type.enum.d.ts +0 -19
- package/lib/shared/enums/common/view-mode.enum.d.ts +0 -4
- package/lib/shared/enums/controls/control.enum.d.ts +0 -11
- package/lib/shared/enums/fields/date-field.enum.d.ts +0 -4
- package/lib/shared/enums/fields/field.enum.d.ts +0 -20
- package/lib/shared/enums/fields/input-field.enum.d.ts +0 -6
- package/lib/shared/enums/fields/input-formatted-field.enum.d.ts +0 -6
- package/lib/shared/enums/fields/select-field.enum.d.ts +0 -4
- package/lib/shared/enums/fields/upload-field.enum.d.ts +0 -5
- package/lib/shared/enums/form/dynamic-form.enum.d.ts +0 -6
- package/lib/shared/enums/validators/regex.enum.d.ts +0 -38
- package/lib/shared/enums/validators/validators.enum.d.ts +0 -14
- package/lib/shared/factories/auto-numeric-options.factory.d.ts +0 -5
- package/lib/shared/models/common/api-config.model.d.ts +0 -4
- package/lib/shared/models/common/api-response.model.d.ts +0 -19
- package/lib/shared/models/common/common.model.d.ts +0 -29
- package/lib/shared/models/common/field-dependency.model.d.ts +0 -16
- package/lib/shared/models/common/file-config.model.d.ts +0 -11
- package/lib/shared/models/common/obj-field.model.d.ts +0 -59
- package/lib/shared/models/common/object-storage.model.d.ts +0 -15
- package/lib/shared/models/common/table-models.d.ts +0 -15
- package/lib/shared/models/fields/date/base-date-field.model.d.ts +0 -19
- package/lib/shared/models/fields/date/date-picker-field.model.d.ts +0 -12
- package/lib/shared/models/fields/date/date-range-field.model.d.ts +0 -12
- package/lib/shared/models/fields/field-grid.model.d.ts +0 -9
- package/lib/shared/models/fields/field-group.model.d.ts +0 -21
- package/lib/shared/models/fields/field-user-config.model.d.ts +0 -3
- package/lib/shared/models/fields/field.model.d.ts +0 -57
- package/lib/shared/models/fields/input/input-field.model.d.ts +0 -31
- package/lib/shared/models/fields/input/input-formatted-field.model.d.ts +0 -13
- package/lib/shared/models/fields/input/input-password-field.model.d.ts +0 -11
- package/lib/shared/models/fields/input/input-text-field.model.d.ts +0 -9
- package/lib/shared/models/fields/radio/radio-base-field.model.d.ts +0 -26
- package/lib/shared/models/fields/select/multi-select-field.model.d.ts +0 -11
- package/lib/shared/models/fields/select/select-base-field.model.d.ts +0 -40
- package/lib/shared/models/fields/select/single-select-field.model.d.ts +0 -9
- package/lib/shared/models/fields/select/tree-select-field.model.d.ts +0 -10
- package/lib/shared/models/fields/textarea/textarea-field.model.d.ts +0 -20
- package/lib/shared/models/fields/upload/avatar-upload-field.model.d.ts +0 -9
- package/lib/shared/models/fields/upload/base-upload-field.model.d.ts +0 -25
- package/lib/shared/models/fields/upload/multi-file-upload-field.model.d.ts +0 -10
- package/lib/shared/models/fields/upload/multi-image-upload-field.model.d.ts +0 -12
- package/lib/shared/models/fields/upload/single-file-upload-field.model.d.ts +0 -11
- package/lib/shared/services/dynamic-form.service.d.ts +0 -48
- package/lib/shared/services/field.service.d.ts +0 -41
- package/lib/shared/services/file.service.d.ts +0 -20
- package/lib/shared/services/form-config.service.d.ts +0 -10
- package/lib/shared/services/form-data.service.d.ts +0 -53
- package/lib/shared/services/form-utils.d.ts +0 -5
- package/lib/shared/services/suffix.service.d.ts +0 -12
- package/lib/shared/services/validation.service.d.ts +0 -10
- package/lib/shared/utils/common/common.utils.d.ts +0 -7
- package/lib/shared/utils/date/date.utils.d.ts +0 -6
- package/lib/shared/utils/dynamic-form/dynamic-form.d.ts +0 -11
- package/lib/shared/utils/fields/fields.d.ts +0 -20
- package/lib/shared/utils/file/file.utils.d.ts +0 -4
- package/lib/shared/utils/validators/custom-validators.d.ts +0 -11
- package/lib/shared/utils/validators/default-error-message.d.ts +0 -6
- package/lib/shared/utils/validators/pattern.d.ts +0 -4
- /package/{styles → src/lib/shared/styles}/_common-form.scss +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<div class="flex">
|
|
2
|
+
@if (modeSignal() === formModeEnum.View) {
|
|
3
|
+
@if (field().viewMode === viewModeEnum.form) {
|
|
4
|
+
@if (field().isCurrency) {
|
|
5
|
+
<input
|
|
6
|
+
nz-input
|
|
7
|
+
[ngModel]="viewDisplayValue()"
|
|
8
|
+
class="modeView"
|
|
9
|
+
[currencyMask]="{
|
|
10
|
+
prefix: '',
|
|
11
|
+
suffix: ' VND',
|
|
12
|
+
thousands: ',',
|
|
13
|
+
decimal: '.',
|
|
14
|
+
precision: 2,
|
|
15
|
+
align: 'left',
|
|
16
|
+
}"
|
|
17
|
+
/>
|
|
18
|
+
} @else {
|
|
19
|
+
<input nz-input [value]="viewDisplayValue()" class="modeView" />
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
@if (field().viewMode === viewModeEnum.text) {
|
|
23
|
+
@if (field().isCurrency) {
|
|
24
|
+
<span class="modeView">
|
|
25
|
+
{{
|
|
26
|
+
viewDisplayValue() | currency: "VND" : "symbol" : "1.0-0" : "vi-VN"
|
|
27
|
+
}}
|
|
28
|
+
</span>
|
|
29
|
+
} @else {
|
|
30
|
+
<span class="modeView">{{ viewDisplayValue() }}</span>
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} @else {
|
|
34
|
+
@if (field().isCurrency) {
|
|
35
|
+
<input
|
|
36
|
+
nz-input
|
|
37
|
+
class="input-control"
|
|
38
|
+
[currencyMask]="{
|
|
39
|
+
prefix: '',
|
|
40
|
+
suffix: ' VND',
|
|
41
|
+
thousands: ',',
|
|
42
|
+
decimal: '.',
|
|
43
|
+
precision: 2,
|
|
44
|
+
align: 'left',
|
|
45
|
+
}"
|
|
46
|
+
[(ngModel)]="value"
|
|
47
|
+
[placeholder]="displayPlaceholder()"
|
|
48
|
+
[disabled]="isDisabled"
|
|
49
|
+
(ngModelChange)="handleChangeFormValue($event)"
|
|
50
|
+
(blur)="onTouched()"
|
|
51
|
+
/>
|
|
52
|
+
} @else {
|
|
53
|
+
<input
|
|
54
|
+
nz-input
|
|
55
|
+
class="input-control"
|
|
56
|
+
[value]="value"
|
|
57
|
+
[placeholder]="displayPlaceholder()"
|
|
58
|
+
[disabled]="isDisabled"
|
|
59
|
+
(input)="handleChangeInputText($event)"
|
|
60
|
+
(blur)="onTouched()"
|
|
61
|
+
/>
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
<!-- Suffixes -->
|
|
66
|
+
@if (field().suffixes.length > 0) {
|
|
67
|
+
@for (suffix of field().suffixes; track $index) {
|
|
68
|
+
@if (suffix.visibleOn?.includes(this.modeSignal())) {
|
|
69
|
+
<app-suffix [suffixConfig]="suffix" [formId]="formId"> </app-suffix>
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
</div>
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { InputTextComponent } from './input-text.component';
|
|
4
|
+
|
|
5
|
+
describe('InputTextComponent', () => {
|
|
6
|
+
let component: InputTextComponent;
|
|
7
|
+
let fixture: ComponentFixture<InputTextComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
imports: [InputTextComponent],
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(InputTextComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
computed,
|
|
4
|
+
effect,
|
|
5
|
+
forwardRef,
|
|
6
|
+
inject,
|
|
7
|
+
untracked,
|
|
8
|
+
} from "@angular/core";
|
|
9
|
+
import { FormsModule, NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
10
|
+
import { InputTextField } from "../../../../models/fields/input";
|
|
11
|
+
import {
|
|
12
|
+
createInputPlaceholder,
|
|
13
|
+
createPlaceholder,
|
|
14
|
+
} from "../../../../utils/dynamic-form/dynamic-form";
|
|
15
|
+
import { BaseValueAccessor } from "../../../../base/base-value-accessor";
|
|
16
|
+
import { FieldTypeEnum } from "../../../../enums/fields";
|
|
17
|
+
import { NO_INFO_TEXT } from "../../../../consts/common";
|
|
18
|
+
import { ControlTypeEnum } from "../../../../enums/controls";
|
|
19
|
+
import { SuffixComponent } from "../../components/suffix/suffix.component";
|
|
20
|
+
import { NzInputModule } from "ng-zorro-antd/input";
|
|
21
|
+
import { CommonModule, CurrencyPipe } from "@angular/common";
|
|
22
|
+
import { NgxCurrencyDirective } from "ngx-currency";
|
|
23
|
+
|
|
24
|
+
const ZORRO_MODULES = [
|
|
25
|
+
NzInputModule,
|
|
26
|
+
NgxCurrencyDirective,
|
|
27
|
+
CurrencyPipe,
|
|
28
|
+
CommonModule,
|
|
29
|
+
FormsModule,
|
|
30
|
+
];
|
|
31
|
+
const COMPONENTS = [SuffixComponent];
|
|
32
|
+
@Component({
|
|
33
|
+
selector: "app-input-text",
|
|
34
|
+
standalone: true,
|
|
35
|
+
imports: [...ZORRO_MODULES, ...COMPONENTS],
|
|
36
|
+
templateUrl: "./input-text.component.html",
|
|
37
|
+
styleUrls: ["./input-text.component.scss"],
|
|
38
|
+
providers: [
|
|
39
|
+
{
|
|
40
|
+
provide: NG_VALUE_ACCESSOR,
|
|
41
|
+
useExisting: forwardRef(() => InputTextComponent),
|
|
42
|
+
multi: true,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
})
|
|
46
|
+
export class InputTextComponent extends BaseValueAccessor<string> {
|
|
47
|
+
readonly field = computed(() => {
|
|
48
|
+
const base = this.fieldInput();
|
|
49
|
+
if (
|
|
50
|
+
!(base instanceof InputTextField) ||
|
|
51
|
+
(base.type !== FieldTypeEnum.InputText &&
|
|
52
|
+
base.controlType !== ControlTypeEnum.Input)
|
|
53
|
+
) {
|
|
54
|
+
throw new Error("Expected InputTextField");
|
|
55
|
+
}
|
|
56
|
+
return base;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
readonly viewDisplayValue = computed(() => {
|
|
60
|
+
// 1. Nếu không phải View thì không cần quan tâm text này
|
|
61
|
+
if (!this.isView()) return "";
|
|
62
|
+
|
|
63
|
+
// 2. Lấy giá trị từ valueSignal
|
|
64
|
+
const val = this.valueSignal();
|
|
65
|
+
return val ? val : NO_INFO_TEXT;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
constructor() {
|
|
69
|
+
super();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Xử lý tạo placeholder text tự động nếu chưa truyền placeholder vào config của field
|
|
73
|
+
override resolvePlaceholderText(): string {
|
|
74
|
+
return createInputPlaceholder(this.field());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Xử lý khi nhập giá trị mới vào input
|
|
78
|
+
handleChangeInputText(event: Event): void {
|
|
79
|
+
const inputValue = (event.target as HTMLInputElement).value;
|
|
80
|
+
this.propagateValue(inputValue);
|
|
81
|
+
|
|
82
|
+
// Gán data vào đầu ra của form.
|
|
83
|
+
this.patchFormData(this.fieldKey(), inputValue);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
handleChangeFormValue(value: number): void {
|
|
87
|
+
const inputValue = value?.toString();
|
|
88
|
+
this.propagateValue(inputValue);
|
|
89
|
+
this.patchFormData(this.fieldKey(), inputValue);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
protected override writeValueToView(value: string): void {
|
|
93
|
+
if (!this.isAddOrEdit()) return;
|
|
94
|
+
|
|
95
|
+
// Gán data vào đầu ra của form.
|
|
96
|
+
this.patchFormData(this.fieldKey(), value);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<div class="flex">
|
|
2
|
+
@if (modeSignal() === formModeEnum.View) {
|
|
3
|
+
@if (viewMode() === viewModeEnum.form) {
|
|
4
|
+
@if (field().value!.length > 0) {
|
|
5
|
+
<nz-select
|
|
6
|
+
nzAllowClear
|
|
7
|
+
[nzMode]="'multiple'"
|
|
8
|
+
[ngModel]="viewDisplayValue()"
|
|
9
|
+
[nzMaxTagCount]="field().maxTagCount!"
|
|
10
|
+
[nzMaxMultipleCount]="field().maxMultipleCount!"
|
|
11
|
+
[nzDisabled]="true"
|
|
12
|
+
>
|
|
13
|
+
@for (displayOption of viewDisplayValue(); track $index) {
|
|
14
|
+
<nz-option [nzValue]="displayOption" [nzLabel]="displayOption">
|
|
15
|
+
</nz-option>
|
|
16
|
+
}
|
|
17
|
+
</nz-select>
|
|
18
|
+
} @else {
|
|
19
|
+
<input nz-input [value]="displayNoValueText" [disabled]="true" />
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@if (viewMode() === viewModeEnum.text) {
|
|
24
|
+
@if (viewDisplayValue().length) {
|
|
25
|
+
<ul class="view-list">
|
|
26
|
+
@for (label of viewDisplayValue(); track $index) {
|
|
27
|
+
<li>{{ label }}</li>
|
|
28
|
+
}
|
|
29
|
+
</ul>
|
|
30
|
+
} @else {
|
|
31
|
+
<span class="modeView">{{ displayNoValueText }}</span>
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} @else {
|
|
35
|
+
<nz-select
|
|
36
|
+
[id]="fieldKey()"
|
|
37
|
+
nzShowSearch
|
|
38
|
+
nzAllowClear
|
|
39
|
+
[nzDisabled]="disabled()"
|
|
40
|
+
[nzMode]="'multiple'"
|
|
41
|
+
[nzPlaceHolder]="displayPlaceholder()"
|
|
42
|
+
[nzMaxTagCount]="field().maxTagCount!"
|
|
43
|
+
[nzMaxMultipleCount]="field().maxMultipleCount!"
|
|
44
|
+
[nzSuffixIcon]="optionsResource.isLoading() ? loadingIcon : null"
|
|
45
|
+
[ngModel]="value"
|
|
46
|
+
(ngModelChange)="handleChangeOptions($event)"
|
|
47
|
+
>
|
|
48
|
+
@for (
|
|
49
|
+
option of options();
|
|
50
|
+
track `${option[this.field().bindValue]}-${$index}`
|
|
51
|
+
) {
|
|
52
|
+
<nz-option
|
|
53
|
+
[nzValue]="transformOptionValue(option)"
|
|
54
|
+
[nzLabel]="getOptionLabel(option)"
|
|
55
|
+
>
|
|
56
|
+
</nz-option>
|
|
57
|
+
}
|
|
58
|
+
</nz-select>
|
|
59
|
+
|
|
60
|
+
<ng-template #loadingIcon>
|
|
61
|
+
<nz-spin nzSimple [nzSize]="'small'"></nz-spin>
|
|
62
|
+
</ng-template>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
<!-- Suffixes -->
|
|
66
|
+
@if (field().suffixes.length > 0) {
|
|
67
|
+
@for (suffix of field().suffixes; track $index) {
|
|
68
|
+
@if (suffix.visibleOn?.includes(this.modeSignal())) {
|
|
69
|
+
<app-suffix [suffixConfig]="suffix" [formId]="formId"> </app-suffix>
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
.view-list {
|
|
2
|
+
margin-bottom: 0;
|
|
3
|
+
padding-inline-start: 24px !important;
|
|
4
|
+
}
|
|
5
|
+
:host ::ng-deep {
|
|
6
|
+
.ant-input[disabled] {
|
|
7
|
+
background-color: white;
|
|
8
|
+
color: #575757 !important;
|
|
9
|
+
// font-size: 12px;
|
|
10
|
+
}
|
|
11
|
+
.ant-select-multiple.ant-select-disabled.ant-select:not(
|
|
12
|
+
.ant-select-customize-input
|
|
13
|
+
)
|
|
14
|
+
.ant-select-selector {
|
|
15
|
+
background: #ffffff;
|
|
16
|
+
}
|
|
17
|
+
.ant-select-disabled.ant-select-multiple .ant-select-selection-item {
|
|
18
|
+
color: #575757;
|
|
19
|
+
// font-size: 12px;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { MultiSelectComponent } from './multi-select.component';
|
|
4
|
+
|
|
5
|
+
describe('MultiSelectComponent', () => {
|
|
6
|
+
let component: MultiSelectComponent;
|
|
7
|
+
let fixture: ComponentFixture<MultiSelectComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
imports: [MultiSelectComponent],
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(MultiSelectComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Component, computed, forwardRef, untracked } from "@angular/core";
|
|
2
|
+
import { CORE_MODULES, FORM_MODULES } from "../../../../consts/common";
|
|
3
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
4
|
+
import { BaseSelectComponent } from "../../../../base/base-select.component";
|
|
5
|
+
import { MultiSelectField } from "../../../../models/fields/select/multi-select-field.model";
|
|
6
|
+
import { createMultiSelectPlaceholder } from "../../../../utils/dynamic-form/dynamic-form";
|
|
7
|
+
import { SelectOutputValueTypeEnum } from "../../../../enums/common";
|
|
8
|
+
import { NO_INFO_TEXT } from "../../../../consts/common/common.const";
|
|
9
|
+
import { FieldTypeEnum } from "../../../../enums/fields";
|
|
10
|
+
import { ControlTypeEnum } from "../../../../enums/controls";
|
|
11
|
+
import { SuffixComponent } from "../../components/suffix/suffix.component";
|
|
12
|
+
import { NzSelectModule } from "ng-zorro-antd/select";
|
|
13
|
+
import { NzInputModule } from "ng-zorro-antd/input";
|
|
14
|
+
import { NzSpinModule } from "ng-zorro-antd/spin";
|
|
15
|
+
|
|
16
|
+
const ZORRO_MODULES = [NzSelectModule, NzInputModule, NzSpinModule];
|
|
17
|
+
const COMPONENTS = [SuffixComponent];
|
|
18
|
+
|
|
19
|
+
@Component({
|
|
20
|
+
selector: "app-multi-select",
|
|
21
|
+
standalone: true,
|
|
22
|
+
imports: [...CORE_MODULES, ...FORM_MODULES, ...ZORRO_MODULES, ...COMPONENTS],
|
|
23
|
+
templateUrl: "./multi-select.component.html",
|
|
24
|
+
styleUrls: ["./multi-select.component.scss"],
|
|
25
|
+
providers: [
|
|
26
|
+
{
|
|
27
|
+
provide: NG_VALUE_ACCESSOR,
|
|
28
|
+
useExisting: forwardRef(() => MultiSelectComponent),
|
|
29
|
+
multi: true,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
export class MultiSelectComponent extends BaseSelectComponent<
|
|
34
|
+
string[] | number[] | Record<string, unknown>[]
|
|
35
|
+
> {
|
|
36
|
+
readonly field = computed(() => {
|
|
37
|
+
const base = this.fieldInput();
|
|
38
|
+
if (
|
|
39
|
+
!(base instanceof MultiSelectField) ||
|
|
40
|
+
(base.type !== FieldTypeEnum.MultiSelect &&
|
|
41
|
+
base.controlType !== ControlTypeEnum.Select)
|
|
42
|
+
) {
|
|
43
|
+
throw new Error("Expected MultiSelectField");
|
|
44
|
+
}
|
|
45
|
+
return base;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
displayNoValueText = NO_INFO_TEXT;
|
|
49
|
+
|
|
50
|
+
// Biến đổi dữ liệu hiển thị ở chế độ View
|
|
51
|
+
viewDisplayValue = computed(() => {
|
|
52
|
+
if (!this.isView()) return [];
|
|
53
|
+
console.log("viewDisplayValue", this.field().modelValue || []);
|
|
54
|
+
|
|
55
|
+
return this.getDisplayValue(this.field().modelValue || []);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
constructor() {
|
|
59
|
+
super();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected override onApiOptionsLoaded(): void {
|
|
63
|
+
const field = this.field();
|
|
64
|
+
if (field.outputAs === SelectOutputValueTypeEnum.SourceObject) {
|
|
65
|
+
const newOutputValue =
|
|
66
|
+
this.value && this.getValueByOutputAs(this.value as string[]);
|
|
67
|
+
this.patchFormData(this.fieldKey(), newOutputValue);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Xử lý tạo placeholder text tự động nếu chưa truyền placeholder vào config của field
|
|
72
|
+
override resolvePlaceholderText(): string {
|
|
73
|
+
return createMultiSelectPlaceholder(this.field());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
handleChangeOptions(optionValue: string[]): void {
|
|
77
|
+
this.propagateValue(optionValue);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Chạy khi value form được gán bởi các hàm reset, patchValue, setValue.
|
|
81
|
+
protected override writeValueToView(value: string[]): void {
|
|
82
|
+
if (!this.isAddOrEdit()) return;
|
|
83
|
+
|
|
84
|
+
this.fieldService.emitDependValueChange(
|
|
85
|
+
this.fieldKey(),
|
|
86
|
+
value.length ? value.join(",") : "",
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Gán data vào đầu ra của form.
|
|
90
|
+
const newOutputValue = value && this.getValueByOutputAs(value);
|
|
91
|
+
this.patchFormData(this.fieldKey(), newOutputValue);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Xử lý phụ thuộc khi change value
|
|
95
|
+
protected override handleValueChange(value: string[]): void {
|
|
96
|
+
const { isParent } = this.field();
|
|
97
|
+
if (isParent) {
|
|
98
|
+
console.log("cscs");
|
|
99
|
+
|
|
100
|
+
this.fieldService.emitDependValueChange(
|
|
101
|
+
this.fieldKey(),
|
|
102
|
+
value.length ? value.join(",") : "",
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const newOutputValue = value && this.getValueByOutputAs(value);
|
|
107
|
+
this.patchFormData(this.fieldKey(), newOutputValue);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Xử lý output value đầu ra theo outputAs mà người dùng mong muốn.
|
|
111
|
+
private getValueByOutputAs(
|
|
112
|
+
singleValueArr: string[] | number[],
|
|
113
|
+
): string[] | Record<string, unknown>[] {
|
|
114
|
+
const field = this.field();
|
|
115
|
+
const { outputAs, bindValue, modelValue } = field;
|
|
116
|
+
|
|
117
|
+
if (singleValueArr.length === 0) {
|
|
118
|
+
return singleValueArr.map(String);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Nếu outputAs là dạng single.
|
|
122
|
+
let value: string[] | Record<string, unknown>[] =
|
|
123
|
+
singleValueArr.map(String);
|
|
124
|
+
|
|
125
|
+
// Nếu outputAs là dạng object.
|
|
126
|
+
if (outputAs === SelectOutputValueTypeEnum.Object) {
|
|
127
|
+
value = value.map((val) => ({
|
|
128
|
+
[bindValue]: val,
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Nếu outputAs là dạng SourceObject.
|
|
133
|
+
if (outputAs === SelectOutputValueTypeEnum.SourceObject) {
|
|
134
|
+
const options = untracked(() => this.options());
|
|
135
|
+
value = (singleValueArr as string[]).map((val) => {
|
|
136
|
+
// 1. Tìm trong options hiện tại
|
|
137
|
+
let foundValue = options.find((opt) => opt[bindValue] === val);
|
|
138
|
+
|
|
139
|
+
// 2. Fallback tìm trong modelValue (vì modelValue có thể là array of objects)
|
|
140
|
+
// if (!foundValue && modelValue && Array.isArray(modelValue)) {
|
|
141
|
+
// foundValue = modelValue.find(
|
|
142
|
+
// (mOpt: any) => typeof mOpt === "object" && mOpt[bindValue] === val
|
|
143
|
+
// );
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
// 3. Fallback cuối cùng
|
|
147
|
+
return foundValue ?? { [bindValue]: val };
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Làm phẳng giá trị để hiện thị ở chế độ View.
|
|
155
|
+
protected getDisplayValue(value: string[] | Record<string, unknown>[]) {
|
|
156
|
+
const optionsValue = value!.map(
|
|
157
|
+
(val: string | number | Record<string, unknown>) => {
|
|
158
|
+
if (typeof val === "object") {
|
|
159
|
+
return this.getCustomLabel(val);
|
|
160
|
+
}
|
|
161
|
+
return val as string;
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return optionsValue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
protected transformOptionValue(option: Record<string, unknown>): unknown {
|
|
169
|
+
const field = this.field();
|
|
170
|
+
|
|
171
|
+
let optionValue: unknown;
|
|
172
|
+
|
|
173
|
+
optionValue = option[field.bindValue];
|
|
174
|
+
|
|
175
|
+
return optionValue;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
protected getOptionLabel(option: Record<string, unknown>): string {
|
|
179
|
+
return this.getCustomLabel(option);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Biến đổi label nếu có thuộc tính hàm biến đổi transformLabel.
|
|
183
|
+
private getCustomLabel(option: Record<string, unknown>): string {
|
|
184
|
+
const field = this.field();
|
|
185
|
+
|
|
186
|
+
// 1. Ưu tiên lấy bindLabel, nếu không có thì fallback sang bindValue
|
|
187
|
+
let rawLabel = option[field.bindLabel];
|
|
188
|
+
if (rawLabel === undefined || rawLabel === null || rawLabel === "") {
|
|
189
|
+
rawLabel = option[field.bindValue];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 2. Kiểm tra nếu không tồn tại hoặc là dạng object/function (kể cả array)
|
|
193
|
+
if (
|
|
194
|
+
rawLabel === undefined ||
|
|
195
|
+
rawLabel === null ||
|
|
196
|
+
typeof rawLabel === "object" ||
|
|
197
|
+
typeof rawLabel === "function"
|
|
198
|
+
) {
|
|
199
|
+
return NO_INFO_TEXT;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
let optionLabel = String(rawLabel);
|
|
203
|
+
|
|
204
|
+
// 3. Biến đổi theo transformLabel nếu có
|
|
205
|
+
if (field.transformLabel) {
|
|
206
|
+
const tranformLabelValue = field.transformLabel(option);
|
|
207
|
+
if (tranformLabelValue) optionLabel = tranformLabelValue;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return optionLabel;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<div class="d-flex">
|
|
2
|
+
@if (isView()) {
|
|
3
|
+
@if (viewMode() === viewModeEnum.form) {
|
|
4
|
+
<input
|
|
5
|
+
[title]="viewDisplayValue()"
|
|
6
|
+
nz-input
|
|
7
|
+
[value]="viewDisplayValue()"
|
|
8
|
+
class="modeView"
|
|
9
|
+
/>
|
|
10
|
+
}
|
|
11
|
+
@if (viewMode() === viewModeEnum.text) {
|
|
12
|
+
<span [title]="viewDisplayValue()" class="modeView break-work">{{
|
|
13
|
+
viewDisplayValue()
|
|
14
|
+
}}</span>
|
|
15
|
+
}
|
|
16
|
+
} @else {
|
|
17
|
+
<nz-select
|
|
18
|
+
[id]="fieldKey()"
|
|
19
|
+
nzShowSearch
|
|
20
|
+
nzAllowClear
|
|
21
|
+
[nzDisabled]="disabled()"
|
|
22
|
+
[nzPlaceHolder]="displayPlaceholder()"
|
|
23
|
+
[nzSuffixIcon]="optionsResource.isLoading() ? loadingIcon : null"
|
|
24
|
+
[title]="field().tooltip || ''"
|
|
25
|
+
[nzDropdownMatchSelectWidth]="field().matchSelectWidth"
|
|
26
|
+
[ngModel]="value"
|
|
27
|
+
class="flex-1 min-w-0"
|
|
28
|
+
(ngModelChange)="handleChangeOptions($event)"
|
|
29
|
+
>
|
|
30
|
+
@for (
|
|
31
|
+
option of options();
|
|
32
|
+
track `${option[this.field().bindValue]}-${$index}`
|
|
33
|
+
) {
|
|
34
|
+
<nz-option
|
|
35
|
+
[nzValue]="transformOptionValue(option)"
|
|
36
|
+
[nzLabel]="getOptionLabel(option)"
|
|
37
|
+
>
|
|
38
|
+
</nz-option>
|
|
39
|
+
}
|
|
40
|
+
</nz-select>
|
|
41
|
+
|
|
42
|
+
<ng-template #loadingIcon>
|
|
43
|
+
<nz-spin nzSimple [nzSize]="'small'"></nz-spin>
|
|
44
|
+
</ng-template>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
<!-- Suffixes -->
|
|
48
|
+
@if (field().suffixes.length > 0) {
|
|
49
|
+
@for (suffix of field().suffixes; track $index) {
|
|
50
|
+
@if (suffix.visibleOn?.includes(this.modeSignal())) {
|
|
51
|
+
<app-suffix [suffixConfig]="suffix" [formId]="formId"> </app-suffix>
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { SingleSelectComponent } from './single-select.component';
|
|
4
|
+
|
|
5
|
+
describe('SingleSelectComponent', () => {
|
|
6
|
+
let component: SingleSelectComponent;
|
|
7
|
+
let fixture: ComponentFixture<SingleSelectComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
imports: [SingleSelectComponent],
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(SingleSelectComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|