@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,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
computed,
|
|
4
|
+
effect,
|
|
5
|
+
forwardRef,
|
|
6
|
+
untracked,
|
|
7
|
+
} from "@angular/core";
|
|
8
|
+
import { FORM_MODULES } from "../../../../consts/common";
|
|
9
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
10
|
+
import { BaseValueAccessor } from "../../../../base/base-value-accessor";
|
|
11
|
+
import { DatePickerField } from "../../../../models/fields/date/date-picker-field.model";
|
|
12
|
+
|
|
13
|
+
import { differenceInCalendarDays } from "date-fns";
|
|
14
|
+
import { DatePickerOutputValueTypeEnum } from "../../../../enums/common";
|
|
15
|
+
import {
|
|
16
|
+
formatDateToDDMMYYYY,
|
|
17
|
+
formatDateToYYYYMMDD,
|
|
18
|
+
} from "../../../../utils/date";
|
|
19
|
+
import { DatePickerOutputValueType } from "../../../../models/common/output-value-type.model";
|
|
20
|
+
import { NO_INFO_TEXT } from "../../../../consts/common/common.const";
|
|
21
|
+
import { FieldTypeEnum } from "../../../../enums/fields";
|
|
22
|
+
import { ControlTypeEnum } from "../../../../enums/controls";
|
|
23
|
+
import { NzDatePickerModule } from "ng-zorro-antd/date-picker";
|
|
24
|
+
import { NzInputModule } from "ng-zorro-antd/input";
|
|
25
|
+
import { FormUtils } from "../../../../services/form-utils";
|
|
26
|
+
import { createDatePickerPlaceholder } from "../../../../utils/dynamic-form/dynamic-form";
|
|
27
|
+
|
|
28
|
+
const ZORRO_MODULES = [NzDatePickerModule, NzInputModule];
|
|
29
|
+
|
|
30
|
+
@Component({
|
|
31
|
+
selector: "app-date-picker",
|
|
32
|
+
standalone: true,
|
|
33
|
+
imports: [...FORM_MODULES, ...ZORRO_MODULES],
|
|
34
|
+
templateUrl: "./date-picker.component.html",
|
|
35
|
+
styleUrls: ["./date-picker.component.scss"],
|
|
36
|
+
providers: [
|
|
37
|
+
{
|
|
38
|
+
provide: NG_VALUE_ACCESSOR,
|
|
39
|
+
useExisting: forwardRef(() => DatePickerComponent),
|
|
40
|
+
multi: true,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
})
|
|
44
|
+
export class DatePickerComponent extends BaseValueAccessor<string | Date> {
|
|
45
|
+
readonly field = computed(() => {
|
|
46
|
+
const base = this.fieldInput();
|
|
47
|
+
if (
|
|
48
|
+
!(base instanceof DatePickerField) ||
|
|
49
|
+
(base.type !== FieldTypeEnum.DatePicker &&
|
|
50
|
+
base.controlType !== ControlTypeEnum.Date)
|
|
51
|
+
) {
|
|
52
|
+
throw new Error("Expected DatePickerField");
|
|
53
|
+
}
|
|
54
|
+
return base;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Định dạng ngày
|
|
58
|
+
format = computed(() => {
|
|
59
|
+
return this.field().format ?? "dd-MM-yyyy";
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Kiểm tra có cho phép chọn ngày quá khứ hay ngày tương lai hay không?
|
|
63
|
+
disabledDate = computed(() => {
|
|
64
|
+
const field = this.field();
|
|
65
|
+
|
|
66
|
+
return (current: Date): boolean => {
|
|
67
|
+
if (field.disabledDateFn) {
|
|
68
|
+
return field.disabledDateFn(current);
|
|
69
|
+
}
|
|
70
|
+
const today = new Date();
|
|
71
|
+
const diff = differenceInCalendarDays(current, today);
|
|
72
|
+
|
|
73
|
+
// if (field.onlyToday) return diff !== 0;
|
|
74
|
+
if (!field.allowPastDates && diff < 0) return true;
|
|
75
|
+
if (!field.allowFutureDates && diff > 0) return true;
|
|
76
|
+
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
readonly viewDisplayValue = computed(() => {
|
|
82
|
+
// 1. Nếu không phải View thì không cần quan tâm text này
|
|
83
|
+
if (!this.isView()) return "";
|
|
84
|
+
|
|
85
|
+
// 2. Lấy giá trị từ valueSignal
|
|
86
|
+
const val = this.valueSignal() as Date;
|
|
87
|
+
return val ? FormUtils.convertViewDate(val, this.format()) : NO_INFO_TEXT;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
constructor() {
|
|
91
|
+
super();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Xử lý tạo placeholder text tự động nếu chưa truyền placeholder vào config của field
|
|
95
|
+
override resolvePlaceholderText(): string {
|
|
96
|
+
return createDatePickerPlaceholder(this.field());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Sự kiện khi người dùng chọn ngày
|
|
100
|
+
handleChangeDate(date: Date): void {
|
|
101
|
+
this.propagateValue(date);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Chạy khi value form được gán bởi các hàm reset, patchValue, setValue
|
|
105
|
+
protected override writeValueToView(value: Date): void {
|
|
106
|
+
if (!this.isAddOrEdit()) return;
|
|
107
|
+
|
|
108
|
+
const { outputAs } = this.field();
|
|
109
|
+
|
|
110
|
+
this.fieldService.updateDependValuesMap(
|
|
111
|
+
this.fieldKey(),
|
|
112
|
+
value ? formatDateToYYYYMMDD(value) : "",
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// Gán data vào đầu ra của form
|
|
116
|
+
const newOutputValue = value && this.getValueByOutputAs(value, outputAs);
|
|
117
|
+
this.patchFormData(this.fieldKey(), newOutputValue);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Xử lý phụ thuộc khi change value
|
|
121
|
+
protected override handleValueChange(value: Date): void {
|
|
122
|
+
const { outputAs, isParent } = this.field();
|
|
123
|
+
|
|
124
|
+
if (isParent) {
|
|
125
|
+
this.fieldService.updateDependValuesMap(
|
|
126
|
+
this.fieldKey(),
|
|
127
|
+
value ? formatDateToYYYYMMDD(value) : "",
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Gán data vào đầu ra của form
|
|
132
|
+
const newOutputValue = value && this.getValueByOutputAs(value, outputAs);
|
|
133
|
+
this.patchFormData(this.fieldKey(), newOutputValue);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Biến đổi giá trị đầu ra theo outputAs
|
|
137
|
+
private getValueByOutputAs(
|
|
138
|
+
date: Date,
|
|
139
|
+
outputAs: DatePickerOutputValueType,
|
|
140
|
+
): string | Date {
|
|
141
|
+
let value: string | Date = date;
|
|
142
|
+
|
|
143
|
+
if (outputAs === DatePickerOutputValueTypeEnum.String) {
|
|
144
|
+
value = formatDateToYYYYMMDD(value);
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@if (modeSignal() === formModeEnum.View) {
|
|
2
|
+
@if (valueSignal()!.length > 0) {
|
|
3
|
+
<nz-range-picker
|
|
4
|
+
[class]="'w-100'"
|
|
5
|
+
[nzFormat]="format()"
|
|
6
|
+
[nzDisabled]="true"
|
|
7
|
+
[ngModel]="valueSignal()"
|
|
8
|
+
class="modeView"
|
|
9
|
+
[nzSuffixIcon]="suffixIcon"
|
|
10
|
+
></nz-range-picker>
|
|
11
|
+
<ng-template #suffixIcon>
|
|
12
|
+
<!-- Để trống, hoặc custom icon khác -->
|
|
13
|
+
</ng-template>
|
|
14
|
+
} @else {
|
|
15
|
+
<input
|
|
16
|
+
nz-input
|
|
17
|
+
[value]="displayValueNoInfo"
|
|
18
|
+
[disabled]="true"
|
|
19
|
+
class="modeView"
|
|
20
|
+
/>
|
|
21
|
+
}
|
|
22
|
+
} @else {
|
|
23
|
+
<nz-range-picker
|
|
24
|
+
[id]="fieldKey()"
|
|
25
|
+
class="w-100"
|
|
26
|
+
[nzDisabled]="disabledSignal()"
|
|
27
|
+
[nzFormat]="format()"
|
|
28
|
+
[nzDisabledDate]="disabledDate()"
|
|
29
|
+
[nzPlaceHolder]="placeholders()"
|
|
30
|
+
[ngModel]="valueSignal()"
|
|
31
|
+
(ngModelChange)="handleChangeDateRange($event)"
|
|
32
|
+
></nz-range-picker>
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @use "../../../../styles/common-form";
|
|
2
|
+
|
|
3
|
+
:host ::ng-deep {
|
|
4
|
+
.modeView {
|
|
5
|
+
&.ant-picker.ant-picker-disabled {
|
|
6
|
+
background-color: inherit !important;
|
|
7
|
+
cursor: default;
|
|
8
|
+
pointer-events: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.ant-picker-input > input[disabled] {
|
|
12
|
+
color: #575757 !important;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.modeView {
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
// background-color: white;
|
|
20
|
+
// font-size: 12px;
|
|
21
|
+
color: #575757 !important;
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { DateRangeComponent } from './date-range.component';
|
|
4
|
+
|
|
5
|
+
describe('DateRangeComponent', () => {
|
|
6
|
+
let component: DateRangeComponent;
|
|
7
|
+
let fixture: ComponentFixture<DateRangeComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
imports: [DateRangeComponent],
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(DateRangeComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
computed,
|
|
4
|
+
effect,
|
|
5
|
+
forwardRef,
|
|
6
|
+
untracked,
|
|
7
|
+
} from "@angular/core";
|
|
8
|
+
import { FORM_MODULES } from "../../../../consts/common";
|
|
9
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
10
|
+
import { BaseValueAccessor } from "../../../../base/base-value-accessor";
|
|
11
|
+
import { DateRangeField } from "../../../../models/fields/date/date-range-field.model";
|
|
12
|
+
import { DateRangeOutputValueType } from "../../../../models/common/output-value-type.model";
|
|
13
|
+
import { DateRangeOutputValueTypeEnum } from "../../../../enums/common";
|
|
14
|
+
import { formatDateToYYYYMMDD, normalizeToDate } from "../../../../utils/date";
|
|
15
|
+
import { NO_INFO_TEXT } from "../../../../consts/common/common.const";
|
|
16
|
+
import { differenceInCalendarDays } from "date-fns";
|
|
17
|
+
import { FieldTypeEnum } from "../../../../enums/fields";
|
|
18
|
+
import { ControlTypeEnum } from "../../../../enums/controls";
|
|
19
|
+
import { NzDatePickerModule } from "ng-zorro-antd/date-picker";
|
|
20
|
+
import { NzInputModule } from "ng-zorro-antd/input";
|
|
21
|
+
|
|
22
|
+
const ZORRO_MODULES = [NzDatePickerModule, NzInputModule];
|
|
23
|
+
|
|
24
|
+
@Component({
|
|
25
|
+
selector: "app-date-range",
|
|
26
|
+
standalone: true,
|
|
27
|
+
imports: [...FORM_MODULES, ...ZORRO_MODULES],
|
|
28
|
+
templateUrl: "./date-range.component.html",
|
|
29
|
+
styleUrls: ["./date-range.component.scss"],
|
|
30
|
+
providers: [
|
|
31
|
+
{
|
|
32
|
+
provide: NG_VALUE_ACCESSOR,
|
|
33
|
+
useExisting: forwardRef(() => DateRangeComponent),
|
|
34
|
+
multi: true,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
})
|
|
38
|
+
export class DateRangeComponent extends BaseValueAccessor<
|
|
39
|
+
string | string[] | Date[]
|
|
40
|
+
> {
|
|
41
|
+
readonly field = computed(() => {
|
|
42
|
+
const base = this.fieldInput();
|
|
43
|
+
if (
|
|
44
|
+
!(base instanceof DateRangeField) ||
|
|
45
|
+
(base.type !== FieldTypeEnum.DateRange &&
|
|
46
|
+
base.controlType !== ControlTypeEnum.Date)
|
|
47
|
+
) {
|
|
48
|
+
throw new Error("Expected DatePickerField");
|
|
49
|
+
}
|
|
50
|
+
return base;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Định dạng ngày
|
|
54
|
+
format = computed(() => {
|
|
55
|
+
return this.field().format ?? "dd-MM-yyyy";
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
placeholders = computed(() => {
|
|
59
|
+
return this.field().placeholders ?? ["Ngày bắt đầu", "Ngày kết thúc"];
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Nếu mảng date không lớn hơn 2
|
|
63
|
+
displayValueNoInfo = NO_INFO_TEXT;
|
|
64
|
+
|
|
65
|
+
// Kiểm tra có cho phép chọn ngày quá khứ hay ngày tương lai hay không?
|
|
66
|
+
disabledDate = computed(() => {
|
|
67
|
+
const field = this.field();
|
|
68
|
+
return (current: Date): boolean => {
|
|
69
|
+
const today = new Date();
|
|
70
|
+
const diff = differenceInCalendarDays(current, today);
|
|
71
|
+
|
|
72
|
+
// if (field.onlyToday) return diff !== 0;
|
|
73
|
+
if (!field.allowPastDates && diff < 0) return true;
|
|
74
|
+
if (!field.allowFutureDates && diff > 0) return true;
|
|
75
|
+
|
|
76
|
+
return false;
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
constructor() {
|
|
81
|
+
super();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
handleChangeDateRange(dateRange: Date[]): void {
|
|
85
|
+
this.propagateValue(dateRange);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Chạy khi value form được gán bởi các hàm reset, patchValue, setValue.
|
|
89
|
+
protected override writeValueToView(value: Date[]): void {
|
|
90
|
+
if (!this.isAddOrEdit()) return;
|
|
91
|
+
|
|
92
|
+
const { outputAs } = untracked(() => this.field());
|
|
93
|
+
|
|
94
|
+
// Gán data vào đầu ra của form.
|
|
95
|
+
this.patchFormData(
|
|
96
|
+
this.fieldKey(),
|
|
97
|
+
value.length > 0 ? this.getValueByOutputAs(value, outputAs) : null,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Xử lý phụ thuộc khi change value
|
|
102
|
+
protected override handleValueChange(value: Date[]): void {
|
|
103
|
+
const { outputAs } = untracked(() => this.field());
|
|
104
|
+
|
|
105
|
+
// Gán data vào đầu ra của form.
|
|
106
|
+
this.patchFormData(
|
|
107
|
+
this.fieldKey(),
|
|
108
|
+
value.length > 0 ? this.getValueByOutputAs(value, outputAs) : null,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Xử lý output value đầu ra theo outputAs mà người dùng mong muốn.
|
|
113
|
+
private getValueByOutputAs(
|
|
114
|
+
dateRange: Date[],
|
|
115
|
+
outputAs: DateRangeOutputValueType,
|
|
116
|
+
): string | string[] | Date[] {
|
|
117
|
+
let value: string | string[] | Date[] = dateRange;
|
|
118
|
+
|
|
119
|
+
if (dateRange.length > 0) {
|
|
120
|
+
if (outputAs === DateRangeOutputValueTypeEnum.String) {
|
|
121
|
+
value = `${formatDateToYYYYMMDD(dateRange[0])},${formatDateToYYYYMMDD(dateRange[1])}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (outputAs === DateRangeOutputValueTypeEnum.StringArray) {
|
|
125
|
+
value = [
|
|
126
|
+
formatDateToYYYYMMDD(dateRange[0]),
|
|
127
|
+
formatDateToYYYYMMDD(dateRange[1]),
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<div class="flex">
|
|
2
|
+
@if (modeSignal() === formModeEnum.View) {
|
|
3
|
+
@if (viewMode() === viewModeEnum.form) {
|
|
4
|
+
<input nz-input [value]="inputDisplayValues()" class="modeView" />
|
|
5
|
+
}
|
|
6
|
+
@if (viewMode() === viewModeEnum.text) {
|
|
7
|
+
<span class="modeView">{{ inputDisplayValues() }}</span>
|
|
8
|
+
}
|
|
9
|
+
} @else {
|
|
10
|
+
<!-- [value]="value" -->
|
|
11
|
+
|
|
12
|
+
<input
|
|
13
|
+
#inputFormatted
|
|
14
|
+
nz-input
|
|
15
|
+
class="input-control custom-input"
|
|
16
|
+
[placeholder]="displayPlaceholder()"
|
|
17
|
+
[disabled]="isDisabled"
|
|
18
|
+
(input)="handleChangeInputText()"
|
|
19
|
+
(blur)="onTouched()"
|
|
20
|
+
/>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
<!-- Suffixes -->
|
|
24
|
+
@if (field().suffixes.length > 0) {
|
|
25
|
+
@for (suffix of field().suffixes; track $index) {
|
|
26
|
+
@if (suffix.visibleOn?.includes(this.modeSignal())) {
|
|
27
|
+
<app-suffix [suffixConfig]="suffix"> </app-suffix>
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
</div>
|
package/src/lib/shared/components/fields/input/input-formatted/input-formatted.component.spec.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { InputFormattedComponent } from './input-formatted.component';
|
|
4
|
+
|
|
5
|
+
describe('InputTextComponent', () => {
|
|
6
|
+
let component: InputFormattedComponent;
|
|
7
|
+
let fixture: ComponentFixture<InputFormattedComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
imports: [InputFormattedComponent],
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(InputFormattedComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
computed,
|
|
4
|
+
effect,
|
|
5
|
+
ElementRef,
|
|
6
|
+
forwardRef,
|
|
7
|
+
signal,
|
|
8
|
+
untracked,
|
|
9
|
+
viewChild,
|
|
10
|
+
} from "@angular/core";
|
|
11
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
12
|
+
import {
|
|
13
|
+
createInputPlaceholder,
|
|
14
|
+
createPlaceholder,
|
|
15
|
+
} from "../../../../utils/dynamic-form/dynamic-form";
|
|
16
|
+
import { BaseValueAccessor } from "../../../../base/base-value-accessor";
|
|
17
|
+
import { FieldTypeEnum } from "../../../../enums/fields";
|
|
18
|
+
import {
|
|
19
|
+
CORE_MODULES,
|
|
20
|
+
FORM_MODULES,
|
|
21
|
+
NO_INFO_TEXT,
|
|
22
|
+
} from "../../../../consts/common";
|
|
23
|
+
import { ControlTypeEnum } from "../../../../enums/controls";
|
|
24
|
+
import { SuffixComponent } from "../../components/suffix/suffix.component";
|
|
25
|
+
import { InputFormattedField } from "../../../../models/fields/input/input-formatted-field.model";
|
|
26
|
+
import AutoNumeric from "@zeedhi/autonumeric";
|
|
27
|
+
import { AutoNumericOptionsFactory } from "../../../../factories/auto-numeric-options.factory";
|
|
28
|
+
import { NzInputModule } from "ng-zorro-antd/input";
|
|
29
|
+
|
|
30
|
+
const zorroModules = [NzInputModule];
|
|
31
|
+
@Component({
|
|
32
|
+
selector: "app-input-formatted",
|
|
33
|
+
standalone: true,
|
|
34
|
+
imports: [...CORE_MODULES, ...FORM_MODULES, ...zorroModules, SuffixComponent],
|
|
35
|
+
templateUrl: "./input-formatted.component.html",
|
|
36
|
+
styleUrls: ["./input-formatted.component.scss"],
|
|
37
|
+
providers: [
|
|
38
|
+
{
|
|
39
|
+
provide: NG_VALUE_ACCESSOR,
|
|
40
|
+
useExisting: forwardRef(() => InputFormattedComponent),
|
|
41
|
+
multi: true,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
})
|
|
45
|
+
export class InputFormattedComponent extends BaseValueAccessor<string> {
|
|
46
|
+
readonly field = computed(() => {
|
|
47
|
+
const base = this.fieldInput();
|
|
48
|
+
if (
|
|
49
|
+
!(base instanceof InputFormattedField) ||
|
|
50
|
+
(base.type !== FieldTypeEnum.InputFormatted &&
|
|
51
|
+
base.controlType !== ControlTypeEnum.Input)
|
|
52
|
+
) {
|
|
53
|
+
throw new Error("Expected InputFormattedField");
|
|
54
|
+
}
|
|
55
|
+
return base;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
private autoNumeric?: AutoNumeric;
|
|
59
|
+
|
|
60
|
+
readonly inputFormattedEle =
|
|
61
|
+
viewChild<ElementRef<HTMLInputElement>>("inputFormatted");
|
|
62
|
+
|
|
63
|
+
readonly autoNumericOptions = computed(() =>
|
|
64
|
+
AutoNumericOptionsFactory.create(this.field()),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
readonly internalValue = signal<string>("");
|
|
68
|
+
|
|
69
|
+
readonly inputDisplayValues = computed(() => {
|
|
70
|
+
const isView = this.isView();
|
|
71
|
+
const autoNumericOptions = this.autoNumericOptions();
|
|
72
|
+
const value = this.internalValue();
|
|
73
|
+
if (isView) {
|
|
74
|
+
const viewValue = value
|
|
75
|
+
? AutoNumeric.format(value, autoNumericOptions)
|
|
76
|
+
: undefined;
|
|
77
|
+
return viewValue || NO_INFO_TEXT;
|
|
78
|
+
}
|
|
79
|
+
return "";
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
readonly autoNumericLifeCycleEffect = effect((onCleanup) => {
|
|
83
|
+
const nativeEle = this.inputFormattedEle()?.nativeElement;
|
|
84
|
+
const isAddOrEdit = this.isAddOrEdit();
|
|
85
|
+
const autoNumericOptions = untracked(() => this.autoNumericOptions());
|
|
86
|
+
const value = untracked(() => this.valueSignal());
|
|
87
|
+
|
|
88
|
+
// 1. TẠO BIẾN CỤC BỘ Ở ĐÂY (Đây là mấu chốt)
|
|
89
|
+
let localAutoNumeric: AutoNumeric | undefined;
|
|
90
|
+
|
|
91
|
+
if (nativeEle && isAddOrEdit) {
|
|
92
|
+
// 2. Gán vào biến cục bộ
|
|
93
|
+
localAutoNumeric = new AutoNumeric(nativeEle, value, autoNumericOptions);
|
|
94
|
+
// 3. Vẫn cập nhật biến class để xài ở chỗ khác
|
|
95
|
+
this.autoNumeric = localAutoNumeric;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
onCleanup(() => {
|
|
99
|
+
// 4. CHỈ REMOVE BIẾN CỤC BỘ (Không dùng this.autoNumeric ở đây)
|
|
100
|
+
if (localAutoNumeric) {
|
|
101
|
+
localAutoNumeric?.remove();
|
|
102
|
+
|
|
103
|
+
// Dọn dẹp biến class nếu nó đang giữ cái vừa bị remove
|
|
104
|
+
if (this.autoNumeric === localAutoNumeric) {
|
|
105
|
+
this.autoNumeric = undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
constructor() {
|
|
112
|
+
super();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Xử lý tạo placeholder text tự động nếu chưa truyền placeholder vào config của field
|
|
116
|
+
override resolvePlaceholderText(): string {
|
|
117
|
+
const isDisabled = this.field().isDisabled;
|
|
118
|
+
return isDisabled ? NO_INFO_TEXT : createInputPlaceholder(this.field());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// event: Event;
|
|
122
|
+
handleChangeInputText(): void {
|
|
123
|
+
const { key } = this.field();
|
|
124
|
+
// const inputValue = (event.target as HTMLInputElement).value;
|
|
125
|
+
|
|
126
|
+
// Lấy giá trị RAW chuẩn từ AutoNumeric (không lấy event.target.value nữa)
|
|
127
|
+
// Dùng fallback string rỗng nếu chưa có
|
|
128
|
+
const rawNumericValue = this.autoNumeric?.getNumericString() || "";
|
|
129
|
+
|
|
130
|
+
this.propagateValue(rawNumericValue);
|
|
131
|
+
|
|
132
|
+
// Gán data vào đầu ra của form.
|
|
133
|
+
this.patchFormData(key, rawNumericValue.trim());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Chỗ này vẫn xử lý bình thường cho CVA không liên quan đến AutoNumeric.
|
|
137
|
+
protected override writeValueToView(value: string): void {
|
|
138
|
+
// 2. NẾU AutoNumeric ĐÃ ĐƯỢC TẠO (đang ở nhánh Add/Edit), thì ép nó format lại giá trị mới
|
|
139
|
+
if (this.autoNumeric) {
|
|
140
|
+
this.autoNumeric.set(value);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const { key } = untracked(() => this.field());
|
|
144
|
+
|
|
145
|
+
// Gán data vào đầu ra của form.
|
|
146
|
+
this.patchFormData(key, value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<nz-input-group [nzSuffix]="suffixTemplate">
|
|
2
|
+
<input
|
|
3
|
+
nz-input
|
|
4
|
+
[value]="value"
|
|
5
|
+
[type]="passwordVisible ? 'text' : 'password'"
|
|
6
|
+
autocomplete="new-password"
|
|
7
|
+
[placeholder]="displayPlaceholder()"
|
|
8
|
+
(input)="handleChangeInputPassword($event)"
|
|
9
|
+
(blur)="onTouched()"
|
|
10
|
+
/>
|
|
11
|
+
</nz-input-group>
|
|
12
|
+
<ng-template #suffixTemplate>
|
|
13
|
+
<span
|
|
14
|
+
nz-icon
|
|
15
|
+
[nzType]="passwordVisible ? 'eye-invisible' : 'eye'"
|
|
16
|
+
(click)="passwordVisible = !passwordVisible"
|
|
17
|
+
></span>
|
|
18
|
+
</ng-template>
|
|
File without changes
|
package/src/lib/shared/components/fields/input/input-password/input-password.component.spec.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { InputPasswordComponent } from './input-password.component';
|
|
4
|
+
|
|
5
|
+
describe('InputPasswordComponent', () => {
|
|
6
|
+
let component: InputPasswordComponent;
|
|
7
|
+
let fixture: ComponentFixture<InputPasswordComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
imports: [InputPasswordComponent],
|
|
12
|
+
});
|
|
13
|
+
fixture = TestBed.createComponent(InputPasswordComponent);
|
|
14
|
+
component = fixture.componentInstance;
|
|
15
|
+
fixture.detectChanges();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should create', () => {
|
|
19
|
+
expect(component).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Component, computed, effect, forwardRef } from "@angular/core";
|
|
2
|
+
import { InputPasswordField } from "../../../../models/fields/input";
|
|
3
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
4
|
+
import { NzInputModule } from "ng-zorro-antd/input";
|
|
5
|
+
import { BaseValueAccessor } from "../../../../base/base-value-accessor";
|
|
6
|
+
import { NzIconModule } from "ng-zorro-antd/icon";
|
|
7
|
+
import { createInputPlaceholder } from "../../../../utils/dynamic-form/dynamic-form";
|
|
8
|
+
import { FieldTypeEnum } from "../../../../enums/fields";
|
|
9
|
+
import { ControlTypeEnum } from "../../../../enums/controls";
|
|
10
|
+
|
|
11
|
+
const ZORRO_MODULES = [NzInputModule, NzIconModule];
|
|
12
|
+
|
|
13
|
+
@Component({
|
|
14
|
+
selector: "app-input-password",
|
|
15
|
+
standalone: true,
|
|
16
|
+
imports: [...ZORRO_MODULES],
|
|
17
|
+
templateUrl: "./input-password.component.html",
|
|
18
|
+
styleUrls: ["./input-password.component.scss"],
|
|
19
|
+
providers: [
|
|
20
|
+
{
|
|
21
|
+
provide: NG_VALUE_ACCESSOR,
|
|
22
|
+
useExisting: forwardRef(() => InputPasswordComponent),
|
|
23
|
+
multi: true,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
})
|
|
27
|
+
export class InputPasswordComponent extends BaseValueAccessor<string> {
|
|
28
|
+
readonly field = computed(() => {
|
|
29
|
+
const base = this.fieldInput();
|
|
30
|
+
if (
|
|
31
|
+
!(base instanceof InputPasswordField) ||
|
|
32
|
+
(base.type !== FieldTypeEnum.InputPassword &&
|
|
33
|
+
base.controlType !== ControlTypeEnum.Input)
|
|
34
|
+
) {
|
|
35
|
+
throw new Error("Expected InputPasswordField");
|
|
36
|
+
}
|
|
37
|
+
return base;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
passwordVisible = false;
|
|
41
|
+
|
|
42
|
+
constructor() {
|
|
43
|
+
super();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Xử lý tạo placeholder text tự động nếu chưa truyền placeholder vào config của field
|
|
47
|
+
override resolvePlaceholderText(): string {
|
|
48
|
+
return createInputPlaceholder(this.field());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
handleChangeInputPassword(event: Event): void {
|
|
52
|
+
const inputValue = (event.target as HTMLInputElement).value;
|
|
53
|
+
this.propagateValue(inputValue);
|
|
54
|
+
this.patchFormData(this.fieldKey(), inputValue);
|
|
55
|
+
}
|
|
56
|
+
}
|