gd-bs 5.8.7 → 5.9.0
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/build/components/form/control.js +5 -0
- package/build/components/inputGroup/index.js +32 -22
- package/dist/gd-bs-icons.js +1 -1
- package/dist/gd-bs-icons.min.js +1 -1
- package/dist/gd-bs.d.ts +10 -1
- package/dist/gd-bs.js +1 -1
- package/dist/gd-bs.min.js +1 -1
- package/package.json +1 -1
- package/src/components/form/control.ts +6 -0
- package/src/components/inputGroup/index.ts +37 -23
- package/src/components/inputGroup/types.d.ts +10 -1
package/package.json
CHANGED
|
@@ -501,6 +501,12 @@ export class FormControl implements IFormControl {
|
|
|
501
501
|
|
|
502
502
|
// See if this is a textbox
|
|
503
503
|
if (this._tb) {
|
|
504
|
+
// See if this is a file
|
|
505
|
+
if (this._props.type == FormControlTypes.File) {
|
|
506
|
+
// Return the file information
|
|
507
|
+
return this._tb.getFileInfo();
|
|
508
|
+
}
|
|
509
|
+
|
|
504
510
|
// Return the value
|
|
505
511
|
return this._tb.getValue();
|
|
506
512
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IInputGroup, IInputGroupProps } from "./types";
|
|
1
|
+
import { IInputGroup, IInputGroupFileValue, IInputGroupProps } from "./types";
|
|
2
2
|
import { Base } from "../base";
|
|
3
3
|
import { Button } from "../button";
|
|
4
4
|
import { HTML } from "./templates";
|
|
@@ -22,6 +22,7 @@ export enum InputGroupTypes {
|
|
|
22
22
|
* @param props The input group properties.
|
|
23
23
|
*/
|
|
24
24
|
class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
|
|
25
|
+
private _fileValue: IInputGroupFileValue = null;
|
|
25
26
|
private _initFl: boolean = false;
|
|
26
27
|
|
|
27
28
|
// Constructor
|
|
@@ -57,28 +58,10 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
|
|
|
57
58
|
if (label) {
|
|
58
59
|
this.props.id ? label.setAttribute("for", this.props.id) : null;
|
|
59
60
|
|
|
60
|
-
//
|
|
61
|
-
if (this.props.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// Set the text
|
|
66
|
-
let spanText = document.createElement("span");
|
|
67
|
-
spanText.classList.add("form-file-text");
|
|
68
|
-
spanText.innerHTML = this.props.label || "Choose a file...";
|
|
69
|
-
label.appendChild(spanText);
|
|
70
|
-
|
|
71
|
-
// Set the button
|
|
72
|
-
let spanButton = document.createElement("span");
|
|
73
|
-
spanButton.classList.add("form-file-button");
|
|
74
|
-
spanButton.innerHTML = "Browse";
|
|
75
|
-
label.appendChild(spanButton);
|
|
76
|
-
} else {
|
|
77
|
-
// Set the label if it exists
|
|
78
|
-
if (this.props.label) { label.innerHTML = this.props.label; }
|
|
79
|
-
// Else, remove it
|
|
80
|
-
else { this.el.removeChild(label); }
|
|
81
|
-
}
|
|
61
|
+
// Set the label if it exists
|
|
62
|
+
if (this.props.label) { label.innerHTML = this.props.label; }
|
|
63
|
+
// Else, remove it
|
|
64
|
+
else { this.el.removeChild(label); }
|
|
82
65
|
}
|
|
83
66
|
|
|
84
67
|
// See if the label exists
|
|
@@ -186,6 +169,35 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
|
|
|
186
169
|
}, 1);
|
|
187
170
|
});
|
|
188
171
|
}
|
|
172
|
+
|
|
173
|
+
// See if this is a file
|
|
174
|
+
if (this.props.type == InputGroupTypes.File) {
|
|
175
|
+
// Set the change event
|
|
176
|
+
(elInput as HTMLInputElement).addEventListener("change", (ev) => {
|
|
177
|
+
// Get the source file
|
|
178
|
+
let srcFile = ev.target["files"][0];
|
|
179
|
+
if (srcFile) {
|
|
180
|
+
let reader = new FileReader();
|
|
181
|
+
|
|
182
|
+
// Set the file loaded event
|
|
183
|
+
reader.onloadend = (ev) => {
|
|
184
|
+
this._fileValue = {
|
|
185
|
+
data: ev.target.result as any,
|
|
186
|
+
name: srcFile.name
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Set the error
|
|
191
|
+
reader.onerror = (ev: any) => {
|
|
192
|
+
// Log
|
|
193
|
+
console.log("Error reading the file", srcFile, ev.target.error);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Read the file
|
|
197
|
+
reader.readAsArrayBuffer(srcFile);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
189
201
|
}
|
|
190
202
|
}
|
|
191
203
|
|
|
@@ -275,6 +287,8 @@ class _InputGroup extends Base<IInputGroupProps> implements IInputGroup {
|
|
|
275
287
|
* Public Interface
|
|
276
288
|
*/
|
|
277
289
|
|
|
290
|
+
getFileInfo() { return this._fileValue; }
|
|
291
|
+
|
|
278
292
|
getValue() { return this.elTextbox.value; }
|
|
279
293
|
|
|
280
294
|
// Sets the textbox value
|
|
@@ -39,8 +39,14 @@ export const InputGroupTypes: IInputGroupTypes;
|
|
|
39
39
|
import { IBaseProps } from "../types";
|
|
40
40
|
import { IButtonProps } from "../button/types";
|
|
41
41
|
|
|
42
|
+
/** Input Group File Value */
|
|
43
|
+
export interface IInputGroupFileValue {
|
|
44
|
+
data: ArrayBuffer;
|
|
45
|
+
name: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
/**
|
|
43
|
-
*
|
|
49
|
+
* Input Group
|
|
44
50
|
*/
|
|
45
51
|
export interface IInputGroup {
|
|
46
52
|
/** The input group element. */
|
|
@@ -49,6 +55,9 @@ export interface IInputGroup {
|
|
|
49
55
|
/** Reference to the textbox input/textarea element. */
|
|
50
56
|
elTextbox: HTMLInputElement | HTMLTextAreaElement;
|
|
51
57
|
|
|
58
|
+
/** Method to get the file information. */
|
|
59
|
+
getFileInfo: () => IInputGroupFileValue;
|
|
60
|
+
|
|
52
61
|
/** Method to get the value. */
|
|
53
62
|
getValue: () => string;
|
|
54
63
|
|