@hpcc-js/form 3.4.4 → 3.4.6
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/LICENSE +43 -43
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +9 -7
- package/src/Button.ts +52 -52
- package/src/CheckBox.ts +103 -103
- package/src/ColorInput.ts +81 -81
- package/src/FieldForm.ts +49 -49
- package/src/Form.css +90 -90
- package/src/Form.ts +337 -337
- package/src/Input.css +42 -42
- package/src/Input.ts +136 -136
- package/src/InputRange.ts +95 -95
- package/src/OnOff.css +74 -74
- package/src/OnOff.ts +159 -159
- package/src/Radio.ts +83 -83
- package/src/Range.ts +116 -116
- package/src/Select.ts +89 -89
- package/src/Slider.css +40 -40
- package/src/Slider.ts +385 -385
- package/src/TextArea.ts +55 -55
- package/src/__package__.ts +3 -3
- package/src/index.ts +14 -14
package/src/Form.ts
CHANGED
|
@@ -1,337 +1,337 @@
|
|
|
1
|
-
import { d3Event, HTMLWidget, select as d3Select, SVGWidget, Widget, WidgetArray } from "@hpcc-js/common";
|
|
2
|
-
import { Button } from "./Button.ts";
|
|
3
|
-
|
|
4
|
-
import "../src/Form.css";
|
|
5
|
-
|
|
6
|
-
export class Form extends HTMLWidget {
|
|
7
|
-
tbody;
|
|
8
|
-
tfoot;
|
|
9
|
-
btntd;
|
|
10
|
-
_controls;
|
|
11
|
-
_maxCols;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
this._tag = "form";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
data(): any;
|
|
20
|
-
data(_: any): this;
|
|
21
|
-
data(_?: any): any | this {
|
|
22
|
-
if (!arguments.length) {
|
|
23
|
-
const retVal = [];
|
|
24
|
-
this.inputsForEach(function (input) {
|
|
25
|
-
retVal.push(input.value());
|
|
26
|
-
});
|
|
27
|
-
return retVal;
|
|
28
|
-
} else {
|
|
29
|
-
this.inputsForEach(function (input, idx) {
|
|
30
|
-
if (_ && _.length > idx) {
|
|
31
|
-
input.value(_[idx]).render();
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
inputsForEach(callback, scope?) {
|
|
39
|
-
let idx = 0;
|
|
40
|
-
this.inputs().forEach(function (inp) {
|
|
41
|
-
const inpArray = inp instanceof WidgetArray ? inp.content() : [inp];
|
|
42
|
-
inpArray.forEach(function (inp2) {
|
|
43
|
-
if (scope) {
|
|
44
|
-
callback.call(scope, inp2, idx++);
|
|
45
|
-
} else {
|
|
46
|
-
callback(inp2, idx++);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
inputsMap(): { [name: string]: Widget } {
|
|
53
|
-
const retVal: { [name: string]: Widget } = {};
|
|
54
|
-
this.inputs().forEach(function (inp) {
|
|
55
|
-
retVal[inp.name()] = inp;
|
|
56
|
-
});
|
|
57
|
-
return retVal;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
calcMaxColumns() {
|
|
61
|
-
let retVal = 0;
|
|
62
|
-
this.inputs().forEach(function (inputWidget) {
|
|
63
|
-
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
64
|
-
if (inputWidgetArray.length > retVal) {
|
|
65
|
-
retVal = inputWidgetArray.length;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return retVal;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
values(): any;
|
|
72
|
-
values(_: any): this;
|
|
73
|
-
values(_?: any): any | this {
|
|
74
|
-
if (!arguments.length) {
|
|
75
|
-
const dataArr = {};
|
|
76
|
-
this.inputsForEach(function (inp) {
|
|
77
|
-
const type = inp.type ? inp.type() : "text";
|
|
78
|
-
const value = inp.value();
|
|
79
|
-
if (value || !this.omitBlank()) {
|
|
80
|
-
switch (type) {
|
|
81
|
-
case "checkbox":
|
|
82
|
-
dataArr[inp.name()] = inp.value_exists() ? !!inp.value() : undefined;
|
|
83
|
-
break;
|
|
84
|
-
case "number":
|
|
85
|
-
const v = inp.value();
|
|
86
|
-
dataArr[inp.name()] = v === "" ? undefined : +v;
|
|
87
|
-
break;
|
|
88
|
-
case "text":
|
|
89
|
-
default:
|
|
90
|
-
dataArr[inp.name()] = inp.value_exists() ? inp.value() : undefined;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}, this);
|
|
95
|
-
return dataArr;
|
|
96
|
-
} else {
|
|
97
|
-
this.inputsForEach(function (inp) {
|
|
98
|
-
if (_[inp.name()]) {
|
|
99
|
-
inp.value(_[inp.name()]);
|
|
100
|
-
} else if (this.omitBlank()) {
|
|
101
|
-
inp.value("");
|
|
102
|
-
}
|
|
103
|
-
}, this);
|
|
104
|
-
}
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
submit() {
|
|
109
|
-
let isValid = true;
|
|
110
|
-
if (this.validate()) {
|
|
111
|
-
isValid = this.checkValidation();
|
|
112
|
-
}
|
|
113
|
-
if (!this.allowEmptyRequest() && !this.inputs().some(function (w) {
|
|
114
|
-
if (w._class.indexOf("WidgetArray") !== -1) {
|
|
115
|
-
return w.content().some(function (wa) {
|
|
116
|
-
return wa.hasValue();
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return w.hasValue();
|
|
120
|
-
})) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
this.click(isValid ? this.values() : null, null, isValid);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
clear() {
|
|
127
|
-
this.inputsForEach(function (inp) {
|
|
128
|
-
switch (inp.classID()) {
|
|
129
|
-
case "form_Slider":
|
|
130
|
-
if (inp.allowRange()) {
|
|
131
|
-
inp.value([inp.low(), inp.low()]).render();
|
|
132
|
-
} else {
|
|
133
|
-
inp.value(inp.low()).render();
|
|
134
|
-
}
|
|
135
|
-
break;
|
|
136
|
-
case "form_CheckBox":
|
|
137
|
-
inp.value(false).render();
|
|
138
|
-
break;
|
|
139
|
-
case "form_Button":
|
|
140
|
-
/* skip */
|
|
141
|
-
break;
|
|
142
|
-
default:
|
|
143
|
-
inp.value(undefined).render();
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
checkValidation() {
|
|
150
|
-
let ret = true;
|
|
151
|
-
const msgArr = [];
|
|
152
|
-
this.inputsForEach(function (inp) {
|
|
153
|
-
if (!inp.isValid()) {
|
|
154
|
-
msgArr.push("'" + inp.label() + "'" + " value is invalid.");
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
if (msgArr.length > 0) {
|
|
158
|
-
alert(msgArr.join("\n"));
|
|
159
|
-
ret = false;
|
|
160
|
-
}
|
|
161
|
-
return ret;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
enter(domNode, element) {
|
|
165
|
-
super.enter(domNode, element);
|
|
166
|
-
element.on("submit", function () {
|
|
167
|
-
d3Event().preventDefault();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
this._placeholderElement.style("overflow", "auto");
|
|
171
|
-
const table = element
|
|
172
|
-
.append("table")
|
|
173
|
-
;
|
|
174
|
-
this.tbody = table.append("tbody");
|
|
175
|
-
this.tfoot = table.append("tfoot");
|
|
176
|
-
this.btntd = this.tfoot.append("tr").append("td")
|
|
177
|
-
.attr("colspan", 2)
|
|
178
|
-
;
|
|
179
|
-
|
|
180
|
-
const context = this;
|
|
181
|
-
this._controls = [
|
|
182
|
-
new Button()
|
|
183
|
-
.classed({ default: true })
|
|
184
|
-
.value("Submit")
|
|
185
|
-
.on("click", function () {
|
|
186
|
-
context.submit();
|
|
187
|
-
}, true),
|
|
188
|
-
new Button()
|
|
189
|
-
.value("Clear")
|
|
190
|
-
.on("click", function () {
|
|
191
|
-
context.clear();
|
|
192
|
-
}, true)
|
|
193
|
-
];
|
|
194
|
-
const rightJust = context.btntd
|
|
195
|
-
.append("div")
|
|
196
|
-
.style("float", "right")
|
|
197
|
-
;
|
|
198
|
-
this._controls.forEach(function (w) {
|
|
199
|
-
const leftJust = rightJust
|
|
200
|
-
.append("span")
|
|
201
|
-
.style("float", "left")
|
|
202
|
-
;
|
|
203
|
-
w.target(leftJust.node()).render();
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
update(domNode, element) {
|
|
208
|
-
super.update(domNode, element);
|
|
209
|
-
|
|
210
|
-
this._maxCols = this.calcMaxColumns();
|
|
211
|
-
|
|
212
|
-
const context = this;
|
|
213
|
-
const rows = this.tbody.selectAll("tr").data(this.inputs());
|
|
214
|
-
rows.enter().append("tr")
|
|
215
|
-
.each(function (inputWidget, i) {
|
|
216
|
-
const element2 = d3Select(this);
|
|
217
|
-
|
|
218
|
-
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
219
|
-
inputWidgetArray.forEach(function (inputWidget2, idx) {
|
|
220
|
-
element2.append("td")
|
|
221
|
-
.attr("class", "prompt")
|
|
222
|
-
;
|
|
223
|
-
const input = element2.append("td")
|
|
224
|
-
.attr("class", "input")
|
|
225
|
-
;
|
|
226
|
-
if (idx === inputWidgetArray.length - 1 && inputWidgetArray.length < context._maxCols) {
|
|
227
|
-
input.attr("colspan", (context._maxCols - inputWidgetArray.length + 1) * 2);
|
|
228
|
-
}
|
|
229
|
-
inputWidget2.target(input.node()).render();
|
|
230
|
-
if (inputWidget2 instanceof SVGWidget) {
|
|
231
|
-
const bbox = inputWidget2.element().node().getBBox();
|
|
232
|
-
input.style("height", bbox.height + "px");
|
|
233
|
-
inputWidget2.resize().render();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (inputWidget2._inputElement instanceof Array) {
|
|
237
|
-
inputWidget2._inputElement.forEach(function (e) {
|
|
238
|
-
e.on("keyup.form", function (w) {
|
|
239
|
-
setTimeout(function () {
|
|
240
|
-
|
|
241
|
-
context._controls[0].disable(!context.allowEmptyRequest() && !context.inputs().some(function (w2) {
|
|
242
|
-
if (w2._class.indexOf("WidgetArray") !== -1) {
|
|
243
|
-
return w2.content().some(function (wa) {
|
|
244
|
-
return wa.hasValue();
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
return w2.hasValue();
|
|
248
|
-
}));
|
|
249
|
-
}, 100);
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
})
|
|
255
|
-
.merge(rows)
|
|
256
|
-
.each(function (inputWidget, i) {
|
|
257
|
-
const element2 = d3Select(this);
|
|
258
|
-
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
259
|
-
inputWidgetArray.forEach(function (inputWidget2, idx) {
|
|
260
|
-
element2.select("td.prompt")
|
|
261
|
-
.text(inputWidget2.label() + ":")
|
|
262
|
-
;
|
|
263
|
-
});
|
|
264
|
-
})
|
|
265
|
-
;
|
|
266
|
-
rows.each(function (inputWidget, i) {
|
|
267
|
-
if (i === 0 && inputWidget.setFocus) {
|
|
268
|
-
inputWidget.setFocus();
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
rows.exit()
|
|
272
|
-
.each(function (inputWidget, i) {
|
|
273
|
-
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
274
|
-
inputWidgetArray.forEach(function (inputWidget2, idx) {
|
|
275
|
-
inputWidget2.target(null);
|
|
276
|
-
});
|
|
277
|
-
})
|
|
278
|
-
.remove()
|
|
279
|
-
;
|
|
280
|
-
|
|
281
|
-
this.tfoot
|
|
282
|
-
.style("display", this.showSubmit() ? "table-footer-group" : "none")
|
|
283
|
-
;
|
|
284
|
-
this.btntd
|
|
285
|
-
.attr("colspan", this._maxCols * 2)
|
|
286
|
-
;
|
|
287
|
-
|
|
288
|
-
// Disable Submit unless there is data
|
|
289
|
-
if (!this.allowEmptyRequest()) {
|
|
290
|
-
setTimeout(function () {
|
|
291
|
-
context._controls[0].disable(!context.allowEmptyRequest() && !context.inputs().some(function (w) {
|
|
292
|
-
if (w._class.indexOf("WidgetArray") !== -1) {
|
|
293
|
-
return w.content().some(function (wa) {
|
|
294
|
-
return wa.hasValue();
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
return w.hasValue();
|
|
298
|
-
}));
|
|
299
|
-
}, 100);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
exit(domNode, element) {
|
|
305
|
-
this.inputsForEach(input => input.target(null));
|
|
306
|
-
super.exit(domNode, element);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
click(row, col, sel) {
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
Form.prototype._class += " form_Form";
|
|
313
|
-
|
|
314
|
-
export interface Form {
|
|
315
|
-
validate(): boolean;
|
|
316
|
-
validate(_: boolean): this;
|
|
317
|
-
validate_exists(): boolean;
|
|
318
|
-
inputs(): any[];
|
|
319
|
-
inputs(_: any[]): this;
|
|
320
|
-
inputs_exists(): boolean;
|
|
321
|
-
inputs_reset(): void;
|
|
322
|
-
showSubmit(): boolean;
|
|
323
|
-
showSubmit(_: boolean): this;
|
|
324
|
-
showSubmit_exists(): boolean;
|
|
325
|
-
omitBlank(): boolean;
|
|
326
|
-
omitBlank(_: boolean): this;
|
|
327
|
-
omitBlank_exists(): boolean;
|
|
328
|
-
allowEmptyRequest(): boolean;
|
|
329
|
-
allowEmptyRequest(_: boolean): this;
|
|
330
|
-
allowEmptyRequest_exists(): boolean;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
Form.prototype.publish("validate", true, "boolean", "Enable/Disable input validation");
|
|
334
|
-
Form.prototype.publish("inputs", [], "widgetArray", "Array of input widgets", null, { render: false });
|
|
335
|
-
Form.prototype.publish("showSubmit", true, "boolean", "Show Submit/Cancel Controls");
|
|
336
|
-
Form.prototype.publish("omitBlank", false, "boolean", "Drop Blank Fields From Submit");
|
|
337
|
-
Form.prototype.publish("allowEmptyRequest", false, "boolean", "Allow Blank Form to be Submitted");
|
|
1
|
+
import { d3Event, HTMLWidget, select as d3Select, SVGWidget, Widget, WidgetArray } from "@hpcc-js/common";
|
|
2
|
+
import { Button } from "./Button.ts";
|
|
3
|
+
|
|
4
|
+
import "../src/Form.css";
|
|
5
|
+
|
|
6
|
+
export class Form extends HTMLWidget {
|
|
7
|
+
tbody;
|
|
8
|
+
tfoot;
|
|
9
|
+
btntd;
|
|
10
|
+
_controls;
|
|
11
|
+
_maxCols;
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this._tag = "form";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
data(): any;
|
|
20
|
+
data(_: any): this;
|
|
21
|
+
data(_?: any): any | this {
|
|
22
|
+
if (!arguments.length) {
|
|
23
|
+
const retVal = [];
|
|
24
|
+
this.inputsForEach(function (input) {
|
|
25
|
+
retVal.push(input.value());
|
|
26
|
+
});
|
|
27
|
+
return retVal;
|
|
28
|
+
} else {
|
|
29
|
+
this.inputsForEach(function (input, idx) {
|
|
30
|
+
if (_ && _.length > idx) {
|
|
31
|
+
input.value(_[idx]).render();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
inputsForEach(callback, scope?) {
|
|
39
|
+
let idx = 0;
|
|
40
|
+
this.inputs().forEach(function (inp) {
|
|
41
|
+
const inpArray = inp instanceof WidgetArray ? inp.content() : [inp];
|
|
42
|
+
inpArray.forEach(function (inp2) {
|
|
43
|
+
if (scope) {
|
|
44
|
+
callback.call(scope, inp2, idx++);
|
|
45
|
+
} else {
|
|
46
|
+
callback(inp2, idx++);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
inputsMap(): { [name: string]: Widget } {
|
|
53
|
+
const retVal: { [name: string]: Widget } = {};
|
|
54
|
+
this.inputs().forEach(function (inp) {
|
|
55
|
+
retVal[inp.name()] = inp;
|
|
56
|
+
});
|
|
57
|
+
return retVal;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
calcMaxColumns() {
|
|
61
|
+
let retVal = 0;
|
|
62
|
+
this.inputs().forEach(function (inputWidget) {
|
|
63
|
+
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
64
|
+
if (inputWidgetArray.length > retVal) {
|
|
65
|
+
retVal = inputWidgetArray.length;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return retVal;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
values(): any;
|
|
72
|
+
values(_: any): this;
|
|
73
|
+
values(_?: any): any | this {
|
|
74
|
+
if (!arguments.length) {
|
|
75
|
+
const dataArr = {};
|
|
76
|
+
this.inputsForEach(function (inp) {
|
|
77
|
+
const type = inp.type ? inp.type() : "text";
|
|
78
|
+
const value = inp.value();
|
|
79
|
+
if (value || !this.omitBlank()) {
|
|
80
|
+
switch (type) {
|
|
81
|
+
case "checkbox":
|
|
82
|
+
dataArr[inp.name()] = inp.value_exists() ? !!inp.value() : undefined;
|
|
83
|
+
break;
|
|
84
|
+
case "number":
|
|
85
|
+
const v = inp.value();
|
|
86
|
+
dataArr[inp.name()] = v === "" ? undefined : +v;
|
|
87
|
+
break;
|
|
88
|
+
case "text":
|
|
89
|
+
default:
|
|
90
|
+
dataArr[inp.name()] = inp.value_exists() ? inp.value() : undefined;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, this);
|
|
95
|
+
return dataArr;
|
|
96
|
+
} else {
|
|
97
|
+
this.inputsForEach(function (inp) {
|
|
98
|
+
if (_[inp.name()]) {
|
|
99
|
+
inp.value(_[inp.name()]);
|
|
100
|
+
} else if (this.omitBlank()) {
|
|
101
|
+
inp.value("");
|
|
102
|
+
}
|
|
103
|
+
}, this);
|
|
104
|
+
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
submit() {
|
|
109
|
+
let isValid = true;
|
|
110
|
+
if (this.validate()) {
|
|
111
|
+
isValid = this.checkValidation();
|
|
112
|
+
}
|
|
113
|
+
if (!this.allowEmptyRequest() && !this.inputs().some(function (w) {
|
|
114
|
+
if (w._class.indexOf("WidgetArray") !== -1) {
|
|
115
|
+
return w.content().some(function (wa) {
|
|
116
|
+
return wa.hasValue();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return w.hasValue();
|
|
120
|
+
})) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.click(isValid ? this.values() : null, null, isValid);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
clear() {
|
|
127
|
+
this.inputsForEach(function (inp) {
|
|
128
|
+
switch (inp.classID()) {
|
|
129
|
+
case "form_Slider":
|
|
130
|
+
if (inp.allowRange()) {
|
|
131
|
+
inp.value([inp.low(), inp.low()]).render();
|
|
132
|
+
} else {
|
|
133
|
+
inp.value(inp.low()).render();
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "form_CheckBox":
|
|
137
|
+
inp.value(false).render();
|
|
138
|
+
break;
|
|
139
|
+
case "form_Button":
|
|
140
|
+
/* skip */
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
inp.value(undefined).render();
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
checkValidation() {
|
|
150
|
+
let ret = true;
|
|
151
|
+
const msgArr = [];
|
|
152
|
+
this.inputsForEach(function (inp) {
|
|
153
|
+
if (!inp.isValid()) {
|
|
154
|
+
msgArr.push("'" + inp.label() + "'" + " value is invalid.");
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
if (msgArr.length > 0) {
|
|
158
|
+
alert(msgArr.join("\n"));
|
|
159
|
+
ret = false;
|
|
160
|
+
}
|
|
161
|
+
return ret;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
enter(domNode, element) {
|
|
165
|
+
super.enter(domNode, element);
|
|
166
|
+
element.on("submit", function () {
|
|
167
|
+
d3Event().preventDefault();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
this._placeholderElement.style("overflow", "auto");
|
|
171
|
+
const table = element
|
|
172
|
+
.append("table")
|
|
173
|
+
;
|
|
174
|
+
this.tbody = table.append("tbody");
|
|
175
|
+
this.tfoot = table.append("tfoot");
|
|
176
|
+
this.btntd = this.tfoot.append("tr").append("td")
|
|
177
|
+
.attr("colspan", 2)
|
|
178
|
+
;
|
|
179
|
+
|
|
180
|
+
const context = this;
|
|
181
|
+
this._controls = [
|
|
182
|
+
new Button()
|
|
183
|
+
.classed({ default: true })
|
|
184
|
+
.value("Submit")
|
|
185
|
+
.on("click", function () {
|
|
186
|
+
context.submit();
|
|
187
|
+
}, true),
|
|
188
|
+
new Button()
|
|
189
|
+
.value("Clear")
|
|
190
|
+
.on("click", function () {
|
|
191
|
+
context.clear();
|
|
192
|
+
}, true)
|
|
193
|
+
];
|
|
194
|
+
const rightJust = context.btntd
|
|
195
|
+
.append("div")
|
|
196
|
+
.style("float", "right")
|
|
197
|
+
;
|
|
198
|
+
this._controls.forEach(function (w) {
|
|
199
|
+
const leftJust = rightJust
|
|
200
|
+
.append("span")
|
|
201
|
+
.style("float", "left")
|
|
202
|
+
;
|
|
203
|
+
w.target(leftJust.node()).render();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
update(domNode, element) {
|
|
208
|
+
super.update(domNode, element);
|
|
209
|
+
|
|
210
|
+
this._maxCols = this.calcMaxColumns();
|
|
211
|
+
|
|
212
|
+
const context = this;
|
|
213
|
+
const rows = this.tbody.selectAll("tr").data(this.inputs());
|
|
214
|
+
rows.enter().append("tr")
|
|
215
|
+
.each(function (inputWidget, i) {
|
|
216
|
+
const element2 = d3Select(this);
|
|
217
|
+
|
|
218
|
+
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
219
|
+
inputWidgetArray.forEach(function (inputWidget2, idx) {
|
|
220
|
+
element2.append("td")
|
|
221
|
+
.attr("class", "prompt")
|
|
222
|
+
;
|
|
223
|
+
const input = element2.append("td")
|
|
224
|
+
.attr("class", "input")
|
|
225
|
+
;
|
|
226
|
+
if (idx === inputWidgetArray.length - 1 && inputWidgetArray.length < context._maxCols) {
|
|
227
|
+
input.attr("colspan", (context._maxCols - inputWidgetArray.length + 1) * 2);
|
|
228
|
+
}
|
|
229
|
+
inputWidget2.target(input.node()).render();
|
|
230
|
+
if (inputWidget2 instanceof SVGWidget) {
|
|
231
|
+
const bbox = inputWidget2.element().node().getBBox();
|
|
232
|
+
input.style("height", bbox.height + "px");
|
|
233
|
+
inputWidget2.resize().render();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (inputWidget2._inputElement instanceof Array) {
|
|
237
|
+
inputWidget2._inputElement.forEach(function (e) {
|
|
238
|
+
e.on("keyup.form", function (w) {
|
|
239
|
+
setTimeout(function () {
|
|
240
|
+
|
|
241
|
+
context._controls[0].disable(!context.allowEmptyRequest() && !context.inputs().some(function (w2) {
|
|
242
|
+
if (w2._class.indexOf("WidgetArray") !== -1) {
|
|
243
|
+
return w2.content().some(function (wa) {
|
|
244
|
+
return wa.hasValue();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return w2.hasValue();
|
|
248
|
+
}));
|
|
249
|
+
}, 100);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
})
|
|
255
|
+
.merge(rows)
|
|
256
|
+
.each(function (inputWidget, i) {
|
|
257
|
+
const element2 = d3Select(this);
|
|
258
|
+
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
259
|
+
inputWidgetArray.forEach(function (inputWidget2, idx) {
|
|
260
|
+
element2.select("td.prompt")
|
|
261
|
+
.text(inputWidget2.label() + ":")
|
|
262
|
+
;
|
|
263
|
+
});
|
|
264
|
+
})
|
|
265
|
+
;
|
|
266
|
+
rows.each(function (inputWidget, i) {
|
|
267
|
+
if (i === 0 && inputWidget.setFocus) {
|
|
268
|
+
inputWidget.setFocus();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
rows.exit()
|
|
272
|
+
.each(function (inputWidget, i) {
|
|
273
|
+
const inputWidgetArray = inputWidget instanceof WidgetArray ? inputWidget.content() : [inputWidget];
|
|
274
|
+
inputWidgetArray.forEach(function (inputWidget2, idx) {
|
|
275
|
+
inputWidget2.target(null);
|
|
276
|
+
});
|
|
277
|
+
})
|
|
278
|
+
.remove()
|
|
279
|
+
;
|
|
280
|
+
|
|
281
|
+
this.tfoot
|
|
282
|
+
.style("display", this.showSubmit() ? "table-footer-group" : "none")
|
|
283
|
+
;
|
|
284
|
+
this.btntd
|
|
285
|
+
.attr("colspan", this._maxCols * 2)
|
|
286
|
+
;
|
|
287
|
+
|
|
288
|
+
// Disable Submit unless there is data
|
|
289
|
+
if (!this.allowEmptyRequest()) {
|
|
290
|
+
setTimeout(function () {
|
|
291
|
+
context._controls[0].disable(!context.allowEmptyRequest() && !context.inputs().some(function (w) {
|
|
292
|
+
if (w._class.indexOf("WidgetArray") !== -1) {
|
|
293
|
+
return w.content().some(function (wa) {
|
|
294
|
+
return wa.hasValue();
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return w.hasValue();
|
|
298
|
+
}));
|
|
299
|
+
}, 100);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
exit(domNode, element) {
|
|
305
|
+
this.inputsForEach(input => input.target(null));
|
|
306
|
+
super.exit(domNode, element);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
click(row, col, sel) {
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
Form.prototype._class += " form_Form";
|
|
313
|
+
|
|
314
|
+
export interface Form {
|
|
315
|
+
validate(): boolean;
|
|
316
|
+
validate(_: boolean): this;
|
|
317
|
+
validate_exists(): boolean;
|
|
318
|
+
inputs(): any[];
|
|
319
|
+
inputs(_: any[]): this;
|
|
320
|
+
inputs_exists(): boolean;
|
|
321
|
+
inputs_reset(): void;
|
|
322
|
+
showSubmit(): boolean;
|
|
323
|
+
showSubmit(_: boolean): this;
|
|
324
|
+
showSubmit_exists(): boolean;
|
|
325
|
+
omitBlank(): boolean;
|
|
326
|
+
omitBlank(_: boolean): this;
|
|
327
|
+
omitBlank_exists(): boolean;
|
|
328
|
+
allowEmptyRequest(): boolean;
|
|
329
|
+
allowEmptyRequest(_: boolean): this;
|
|
330
|
+
allowEmptyRequest_exists(): boolean;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
Form.prototype.publish("validate", true, "boolean", "Enable/Disable input validation");
|
|
334
|
+
Form.prototype.publish("inputs", [], "widgetArray", "Array of input widgets", null, { render: false });
|
|
335
|
+
Form.prototype.publish("showSubmit", true, "boolean", "Show Submit/Cancel Controls");
|
|
336
|
+
Form.prototype.publish("omitBlank", false, "boolean", "Drop Blank Fields From Submit");
|
|
337
|
+
Form.prototype.publish("allowEmptyRequest", false, "boolean", "Allow Blank Form to be Submitted");
|