@daracl/form 0.0.12 → 0.0.13

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.
Files changed (49) hide show
  1. package/dist/daracl.form.js +2 -2
  2. package/dist/daracl.form.min.js +2 -2
  3. package/dist/daracl.form.min.js.LICENSE.txt +1 -1
  4. package/dist/daracl.vender.min.js +1 -1
  5. package/dist/main.css +1 -1
  6. package/package.json +3 -5
  7. package/src/DaraForm.ts +0 -431
  8. package/src/FieldInfoMap.ts +0 -356
  9. package/src/FormTemplate.ts +0 -207
  10. package/src/constants.ts +0 -100
  11. package/src/event/renderEvents.ts +0 -41
  12. package/src/index copy.html +0 -591
  13. package/src/index-grid.html +0 -655
  14. package/src/index-tab.html +0 -639
  15. package/src/index.html +0 -485
  16. package/src/indexVender.ts +0 -9
  17. package/src/renderer/ButtonRender.ts +0 -51
  18. package/src/renderer/CheckboxRender.ts +0 -214
  19. package/src/renderer/CustomRender.ts +0 -100
  20. package/src/renderer/DateRender.ts +0 -104
  21. package/src/renderer/DropdownRender.ts +0 -149
  22. package/src/renderer/FileRender.ts +0 -239
  23. package/src/renderer/GridRender.ts +0 -289
  24. package/src/renderer/GroupRender.ts +0 -47
  25. package/src/renderer/HiddenRender.ts +0 -36
  26. package/src/renderer/NumberRender.ts +0 -68
  27. package/src/renderer/PasswordRender.ts +0 -69
  28. package/src/renderer/RadioRender.ts +0 -191
  29. package/src/renderer/RangeRender.ts +0 -79
  30. package/src/renderer/Render.ts +0 -194
  31. package/src/renderer/TabRender.ts +0 -229
  32. package/src/renderer/TextAreaRender.ts +0 -72
  33. package/src/renderer/TextRender.ts +0 -68
  34. package/src/rule/fileValidator.ts +0 -26
  35. package/src/rule/numberValidator.ts +0 -96
  36. package/src/rule/regexpValidator.ts +0 -45
  37. package/src/rule/stringValidator.ts +0 -64
  38. package/src/rule/validator.ts +0 -49
  39. package/src/types/DataMap.d.ts +0 -17
  40. package/src/types/DateTimePicker.d.ts +0 -5
  41. package/src/types/FormField.d.ts +0 -129
  42. package/src/types/FormOptions.d.ts +0 -91
  43. package/src/types/Message.d.ts +0 -40
  44. package/src/types/ValidResult.d.ts +0 -9
  45. package/src/util/Lanauage.ts +0 -127
  46. package/src/util/renderFactory.ts +0 -26
  47. package/src/util/styleUtils.ts +0 -85
  48. package/src/util/utils.ts +0 -283
  49. package/src/util/validUtils.ts +0 -53
@@ -1,214 +0,0 @@
1
- import { FormField, ValuesInfo } from "@t/FormField";
2
- import Render from "./Render";
3
- import * as utils from "src/util/utils";
4
- import { ValidResult } from "@t/ValidResult";
5
- import { RULES } from "src/constants";
6
- import { resetRowElementStyleClass, invalidMessage } from "src/util/validUtils";
7
- import { customChangeEventCall } from "src/event/renderEvents";
8
- import DaraForm from "src/DaraForm";
9
-
10
- export default class CheckboxRender extends Render {
11
- private defaultCheckValue: any[] = [];
12
-
13
- constructor(field: FormField, rowElement: HTMLElement, daraForm: DaraForm) {
14
- super(daraForm, field, rowElement);
15
-
16
- this.defaultCheckValue = [];
17
- let initDefaultValue = [] as any;
18
- if (!utils.isUndefined(field.defaultValue)) {
19
- if (utils.isArray(field.defaultValue)) {
20
- initDefaultValue = field.defaultValue;
21
- } else {
22
- initDefaultValue = [field.defaultValue];
23
- }
24
- }
25
-
26
- const valueKey = CheckboxRender.valuesValueKey(field);
27
-
28
- if (utils.isUndefined(this.field.listItem)) {
29
- this.setValueItems([{ label: "", value: "Y" }]);
30
- }
31
-
32
- let initDefaultValueFlag = false;
33
- this.field.listItem?.list?.forEach((item) => {
34
- let itemValue = item[valueKey];
35
- if (item.selected) {
36
- this.defaultCheckValue.push(itemValue ? itemValue : true);
37
- }
38
- if (initDefaultValue.includes(itemValue)) {
39
- initDefaultValueFlag = true;
40
- }
41
- });
42
-
43
- this.defaultCheckValue = initDefaultValueFlag ? initDefaultValue : this.defaultCheckValue;
44
-
45
- this.mounted();
46
- this.setDefaultOption();
47
- this.setValue(this.defaultCheckValue, false);
48
- }
49
-
50
- public mounted() {
51
- this.initEvent();
52
- }
53
-
54
- public initEvent() {
55
- const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
56
-
57
- checkboxes.forEach((ele) => {
58
- ele.addEventListener("change", (e: Event) => {
59
- customChangeEventCall(this.field, e, this, this.getValue());
60
- this.valid();
61
- });
62
- });
63
- }
64
-
65
- public getSelector() {
66
- return `input[type="checkbox"][name="${this.field.$xssName}"]`;
67
- }
68
-
69
- createField() {
70
- const field = this.field;
71
-
72
- const fieldContainerElement = this.rowElement.querySelector(".df-field-container") as HTMLElement;
73
-
74
- const templates: string[] = [];
75
- const fieldName = field.$xssName;
76
-
77
- const labelKey = Render.valuesLabelKey(field);
78
- const valueKey = Render.valuesValueKey(field);
79
-
80
- templates.push(` <div class="df-field"><div class="field-group">`);
81
- field.listItem?.list?.forEach((val) => {
82
- const checkVal = val[valueKey];
83
- templates.push(`
84
- <span class="field ${field.listItem.orientation == "vertical" ? "vertical" : "horizontal"}">
85
- <label>
86
- <input type="checkbox" name="${fieldName}" value="${checkVal ? utils.replaceXss(checkVal) : ""}" class="form-field checkbox" ${val.selected ? "checked" : ""} ${val.disabled ? "disabled" : ""} />
87
- ${Render.valuesLabelValue(labelKey, val)}
88
- </label>
89
- </span>
90
- `);
91
- });
92
- templates.push(`<i class="daracl-icon help-icon"></i></div></div> ${Render.getDescriptionTemplate(field)}<div class="help-message"></div>`);
93
-
94
- fieldContainerElement.innerHTML = templates.join("");
95
- }
96
-
97
- public setValueItems(items: any): void {
98
- const containerEle = this.rowElement.querySelector(".df-field-container");
99
- if (containerEle) {
100
- if (this.field.listItem) {
101
- this.field.listItem.list = items;
102
- } else {
103
- this.field.listItem = {
104
- list: items,
105
- } as ValuesInfo;
106
- }
107
-
108
- this.createField();
109
-
110
- if (!utils.isBlank(this.field.$value)) {
111
- const currentValue = this.field.$value;
112
- this.field.$value = "";
113
- this.setValue(currentValue);
114
- }
115
- }
116
- }
117
-
118
- getValue() {
119
- const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
120
-
121
- if (checkboxes.length > 1) {
122
- const checkValue: any[] = [];
123
- checkboxes.forEach((ele) => {
124
- const checkEle = ele as HTMLInputElement;
125
- if (checkEle.checked) {
126
- checkValue.push(checkEle.value);
127
- }
128
- });
129
- return checkValue;
130
- } else {
131
- const checkElement = this.rowElement.querySelector(`[name="${this.field.$xssName}"]`) as HTMLInputElement;
132
-
133
- if (checkElement?.checked) {
134
- return checkElement.value ? checkElement.value : true;
135
- }
136
-
137
- return checkElement.value ? "" : false;
138
- }
139
- }
140
-
141
- setValue(value: any, changeCheckFlag?: boolean): void {
142
- if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
143
- value = this.field.$value;
144
- }
145
-
146
- this.field.$value = value;
147
- if (value === true) {
148
- (this.rowElement.querySelector(`[name="${this.field.$xssName}"]`) as HTMLInputElement).checked = true;
149
- return;
150
- }
151
-
152
- if (value === false) {
153
- (this.rowElement.querySelector(`[name="${this.field.$xssName}"]`) as HTMLInputElement).checked = false;
154
- return;
155
- }
156
-
157
- let valueArr: any[] = [];
158
- if (Array.isArray(value)) {
159
- valueArr = value;
160
- } else {
161
- valueArr.push(value);
162
- }
163
-
164
- const checkboxes = this.rowElement.querySelectorAll(this.getSelector());
165
-
166
- checkboxes.forEach((ele) => {
167
- (ele as HTMLInputElement).checked = false;
168
- });
169
-
170
- valueArr.forEach((val) => {
171
- const ele = this.rowElement.querySelector(`[name="${this.field.$xssName}"][value="${val}"]`) as HTMLInputElement;
172
- if (ele) ele.checked = true;
173
- });
174
- }
175
-
176
- reset() {
177
- if (this.field.listItem?.list?.length == 1 && this.defaultCheckValue.length == 1) {
178
- this.setValue(true, false);
179
- } else {
180
- this.setValue(this.defaultCheckValue, false);
181
- }
182
- this.setDisabled(false);
183
- resetRowElementStyleClass(this.rowElement);
184
- }
185
-
186
- getElement(): any {
187
- return this.rowElement.querySelectorAll(`[name="${this.field.$xssName}"]`);
188
- }
189
-
190
- public focus() {
191
- const elements = this.getElement();
192
-
193
- if (elements && elements.length > 0) {
194
- this.getElement()[0].focus();
195
- }
196
- }
197
-
198
- valid(): any {
199
- const value = this.getValue();
200
-
201
- let validResult: ValidResult | boolean = true;
202
-
203
- if (this.field.required && utils.isArray(value)) {
204
- if ((value as any[]).length < 1) {
205
- validResult = { name: this.field.name, constraint: [] };
206
- validResult.constraint.push(RULES.REQUIRED);
207
- }
208
- }
209
-
210
- invalidMessage(this.field, this.rowElement, validResult);
211
-
212
- return validResult;
213
- }
214
- }
@@ -1,100 +0,0 @@
1
- import { FormField } from "@t/FormField";
2
- import Render from "./Render";
3
- import { invalidMessage, resetRowElementStyleClass } from "src/util/validUtils";
4
- import DaraForm from "src/DaraForm";
5
- import * as utils from "src/util/utils";
6
- import { stringValidator } from "src/rule/stringValidator";
7
-
8
- export default class CustomRender extends Render {
9
- private customFunction;
10
-
11
- constructor(field: FormField, rowElement: HTMLElement, daraForm: DaraForm) {
12
- super(daraForm, field, rowElement);
13
- if (field.renderer) {
14
- this.customFunction = field.renderer;
15
- this.mounted();
16
- this.setDefaultOption();
17
- this.setDefaultInfo();
18
- } else {
19
- this.customFunction = {} as any;
20
- }
21
- }
22
-
23
- mounted() {
24
- if (this.customFunction.mounted) {
25
- (this.customFunction.mounted as any).call(this, this.field, this.rowElement);
26
- }
27
- }
28
-
29
- static isDataRender(): boolean {
30
- return false;
31
- }
32
-
33
- createField() {
34
- const field = this.field;
35
-
36
- const fieldTemplate = utils.isEmpty(field.template) ? "" : utils.isString(field.template) ? field.template : field.template();
37
-
38
- const fieldContainerElement = this.rowElement.querySelector(".df-field-container") as HTMLElement;
39
-
40
- fieldContainerElement.innerHTML = ` <div class="df-field">
41
- ${fieldTemplate}
42
- </div>
43
- ${Render.getDescriptionTemplate(field)}
44
- <div class="help-message"></div>`;
45
- }
46
-
47
- getValue() {
48
- if (this.customFunction.getValue) {
49
- return (this.customFunction.getValue as any).call(this, this.field, this.rowElement);
50
- }
51
- return "";
52
- }
53
-
54
- setValue(value: any, changeCheckFlag?: boolean): void {
55
- if (this.customFunction.setValue) {
56
- if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
57
- value = this.field.$value;
58
- }
59
- (this.customFunction.setValue as any).call(this, value, this.field, this.rowElement);
60
- }
61
-
62
- this.field.$value = value;
63
- }
64
-
65
- reset() {
66
- this.setDefaultInfo();
67
- resetRowElementStyleClass(this.rowElement);
68
- }
69
-
70
- getElement() {
71
- if (this.customFunction.getElement) {
72
- return (this.customFunction.getElement as any).call(this, this.field, this.rowElement);
73
- }
74
- return null;
75
- }
76
-
77
- valid(): any {
78
- if (this.customFunction.valid) {
79
- const validResult = (this.customFunction.valid as any).call(this, this.field, this.rowElement);
80
-
81
- invalidMessage(this.field, this.rowElement, validResult);
82
-
83
- return;
84
- }
85
- const validResult = stringValidator(this.getValue(), this.field);
86
-
87
- invalidMessage(this.field, this.rowElement, validResult);
88
-
89
- return validResult;
90
- }
91
-
92
- /**
93
- * focus
94
- */
95
- focus(): void {
96
- if (this.customFunction.focus) {
97
- (this.customFunction.focus as any).call(this, this.field, this.rowElement);
98
- }
99
- }
100
- }
@@ -1,104 +0,0 @@
1
- import { FormField } from "@t/FormField";
2
- import Render from "./Render";
3
- import { stringValidator } from "src/rule/stringValidator";
4
- import { resetRowElementStyleClass, invalidMessage } from "src/util/validUtils";
5
- import DaraForm from "src/DaraForm";
6
- import DateTimePicker from "@daracl/datetimepicker";
7
-
8
- import * as utils from "src/util/utils";
9
-
10
- export default class DateRender extends Render {
11
- private element: HTMLInputElement;
12
- private dateObj: any;
13
-
14
- constructor(field: FormField, rowElement: HTMLElement, daraForm: DaraForm) {
15
- super(daraForm, field, rowElement);
16
-
17
- this.mounted();
18
- this.setDefaultOption();
19
- this.setDefaultInfo();
20
- }
21
-
22
- mounted() {
23
- let dateOnSelectEvent: any;
24
- this.field.customOptions = Object.assign({}, this.field.customOptions);
25
- if (typeof this.field.customOptions.onSelect !== "undefined") {
26
- dateOnSelectEvent = typeof this.field.customOptions.onSelect;
27
- }
28
-
29
- if (utils.isUndefined(this.field.customOptions.mode)) {
30
- if (this.field.renderType == "datemonth" || this.field.renderType == "datehour") {
31
- this.field.customOptions.mode = this.field.renderType.replace("date", "");
32
- } else {
33
- this.field.customOptions.mode = this.field.renderType;
34
- }
35
- }
36
-
37
- this.field.customOptions.onSelect = (dt: any, e: Event) => {
38
- if (dateOnSelectEvent) {
39
- dateOnSelectEvent(dt, e);
40
- }
41
-
42
- this.setValue(dt);
43
-
44
- this.valid();
45
- };
46
-
47
- this.dateObj = new DateTimePicker(this.element, this.field.customOptions, {} as any);
48
-
49
- //this.loadDate();
50
- }
51
-
52
- // async loadDate() {
53
- // const DateTimePicker = await import("@daracl/datetimepicker");
54
- // this.dateObj = new DateTimePicker.default(this.element, this.field.customOptions, {} as any);
55
- // }
56
-
57
- createField() {
58
- const field = this.field;
59
-
60
- const fieldContainerElement = this.rowElement.querySelector(".df-field-container") as HTMLElement;
61
-
62
- fieldContainerElement.innerHTML = `
63
- <div class="df-field">
64
- <input type="text" name="${field.$xssName}" class="form-field text help-icon" autocomplete="off" readonly/>
65
- </div>
66
- ${Render.getDescriptionTemplate(field)}
67
- <div class="help-message"></div>
68
- `;
69
-
70
- this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`) as HTMLInputElement;
71
- }
72
-
73
- getValue() {
74
- return this.element.value;
75
- }
76
-
77
- setValue(value: any, changeCheckFlag?: boolean): void {
78
- if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
79
- this.element.value = this.field.$value;
80
- return;
81
- }
82
-
83
- this.field.$value = value;
84
- this.element.value = value;
85
- }
86
-
87
- reset() {
88
- this.setDefaultInfo();
89
- this.setDisabled(false);
90
- resetRowElementStyleClass(this.rowElement);
91
- }
92
-
93
- getElement(): HTMLInputElement {
94
- return this.element;
95
- }
96
-
97
- valid(): any {
98
- const validResult = stringValidator(this.getValue(), this.field);
99
-
100
- invalidMessage(this.field, this.rowElement, validResult);
101
-
102
- return validResult;
103
- }
104
- }
@@ -1,149 +0,0 @@
1
- import { FormField, ValuesInfo } from "@t/FormField";
2
- import Render from "./Render";
3
- import { ValidResult } from "@t/ValidResult";
4
- import { RULES } from "src/constants";
5
- import { resetRowElementStyleClass, invalidMessage } from "src/util/validUtils";
6
- import { dropdownChangeEvent } from "src/event/renderEvents";
7
- import DaraForm from "src/DaraForm";
8
- import * as utils from "src/util/utils";
9
- import Lanauage from "src/util/Lanauage";
10
-
11
- export default class DropdownRender extends Render {
12
- private element: HTMLSelectElement;
13
- private defaultSelected;
14
-
15
- constructor(field: FormField, rowElement: HTMLElement, daraForm: DaraForm) {
16
- super(daraForm, field, rowElement);
17
-
18
- let initDefaultValue = "";
19
-
20
- if (!utils.isUndefined(field.defaultValue)) {
21
- initDefaultValue = field.defaultValue;
22
- }
23
-
24
- const valueKey = DropdownRender.valuesValueKey(field);
25
- let initDefaultValueFlag = false;
26
- this.field.listItem?.list?.forEach((item) => {
27
- let itemValue = item[valueKey];
28
- if (item.selected) {
29
- this.defaultSelected = itemValue;
30
- }
31
- if (itemValue == initDefaultValue) {
32
- initDefaultValueFlag = true;
33
- }
34
- });
35
-
36
- if (initDefaultValueFlag) {
37
- this.defaultSelected = initDefaultValue;
38
- } else if (!this.defaultSelected) {
39
- if (field.customOptions?.disableDefaultOption === true) {
40
- this.defaultSelected = this.field.listItem?.list?.length > 0 ? this.field.listItem.list[0][valueKey] || "" : "";
41
- }
42
- }
43
-
44
- if (utils.isUndefined(this.defaultSelected)) {
45
- this.defaultSelected = "";
46
- }
47
-
48
- this.mounted();
49
- this.setDefaultOption();
50
- this.setValue(this.defaultSelected, false);
51
- }
52
-
53
- mounted() {
54
- dropdownChangeEvent(this.field, this.element, this);
55
- }
56
-
57
- createField() {
58
- const field = this.field;
59
-
60
- const fieldContainerElement = this.rowElement.querySelector(".df-field-container") as HTMLElement;
61
-
62
- let template = ` <div class="df-field"><select name="${field.$xssName}" class="form-field dropdown">
63
- ${this.dropdownValuesTemplate(field)}
64
- </select> <i class="help-icon"></i></div>
65
- ${Render.getDescriptionTemplate(field)}
66
- <div class="help-message"></div>
67
- `;
68
- fieldContainerElement.innerHTML = template;
69
-
70
- this.element = fieldContainerElement.querySelector(`[name="${field.$xssName}"]`) as HTMLSelectElement;
71
- }
72
-
73
- public setValueItems(items: any): void {
74
- if (this.field.listItem) {
75
- this.field.listItem.list = items;
76
- } else {
77
- this.field.listItem = {
78
- list: items,
79
- } as ValuesInfo;
80
- }
81
- this.element.innerHTML = this.dropdownValuesTemplate(this.field);
82
-
83
- if (!utils.isBlank(this.field.$value)) {
84
- const currentValue = this.field.$value;
85
- this.field.$value = "";
86
- this.setValue(currentValue);
87
- }
88
- }
89
-
90
- getValue() {
91
- return this.element.value;
92
- }
93
-
94
- setValue(value: any, changeCheckFlag?: boolean): void {
95
- if (changeCheckFlag !== false && this.changeEventCall(this.field, null, this, value) === false) {
96
- this.element.value = this.field.$value;
97
- return;
98
- }
99
- this.field.$value = value;
100
- this.element.value = value;
101
- }
102
-
103
- reset() {
104
- this.setValue(this.defaultSelected, false);
105
- this.setDisabled(false);
106
- resetRowElementStyleClass(this.rowElement);
107
- }
108
-
109
- getElement(): HTMLElement {
110
- return this.element;
111
- }
112
-
113
- valid(): any {
114
- const value = this.getValue();
115
-
116
- let validResult: ValidResult | boolean = true;
117
-
118
- if (this.field.required) {
119
- if (value.length < 1) {
120
- validResult = { name: this.field.name, constraint: [] };
121
- validResult.constraint.push(RULES.REQUIRED);
122
- }
123
- }
124
-
125
- invalidMessage(this.field, this.rowElement, validResult);
126
-
127
- return validResult;
128
- }
129
-
130
- public dropdownValuesTemplate(field: FormField) {
131
- const labelKey = Render.valuesLabelKey(field);
132
- const valueKey = Render.valuesValueKey(field);
133
- let template = "";
134
-
135
- if (field.customOptions?.disableDefaultOption !== true) {
136
- template += `<option value="">${Lanauage.getMessage("selection")}</option>`;
137
- }
138
- field.listItem?.list?.forEach((val) => {
139
- const attr = `${val.selected ? "selected" : ""} ${val.disabled ? "disabled" : ""}`;
140
- if (utils.isUndefined(val[valueKey]) && val.label) {
141
- template += `<option value="${val.value || ""}" ${attr}>${val.label}</option>`;
142
- } else {
143
- template += `<option value="${val[valueKey]}" ${attr}>${Render.valuesLabelValue(labelKey, val)}</option>`;
144
- }
145
- });
146
-
147
- return template;
148
- }
149
- }