@syncfusion/ej2-inputs 30.2.4 → 31.1.17
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/dist/ej2-inputs.min.js +2 -2
- package/dist/ej2-inputs.umd.min.js +2 -2
- package/dist/ej2-inputs.umd.min.js.map +1 -1
- package/dist/es6/ej2-inputs.es2015.js +1 -1
- package/dist/es6/ej2-inputs.es2015.js.map +1 -1
- package/dist/es6/ej2-inputs.es5.js +1 -1
- package/dist/es6/ej2-inputs.es5.js.map +1 -1
- package/dist/global/ej2-inputs.min.js +2 -2
- package/dist/global/ej2-inputs.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/dist/ts/color-picker/color-picker-model.d.ts +186 -0
- package/dist/ts/color-picker/color-picker.d.ts +398 -0
- package/dist/ts/color-picker/color-picker.ts +2209 -0
- package/dist/ts/color-picker/index.d.ts +5 -0
- package/dist/ts/color-picker/index.ts +5 -0
- package/dist/ts/common/index.d.ts +4 -0
- package/dist/ts/common/index.ts +4 -0
- package/dist/ts/common/signature-base.d.ts +340 -0
- package/dist/ts/common/signature-base.ts +1170 -0
- package/dist/ts/form-validator/form-validator-model.d.ts +121 -0
- package/dist/ts/form-validator/form-validator.d.ts +312 -0
- package/dist/ts/form-validator/form-validator.ts +1068 -0
- package/dist/ts/form-validator/index.d.ts +5 -0
- package/dist/ts/form-validator/index.ts +5 -0
- package/dist/ts/index.d.ts +18 -0
- package/dist/ts/index.ts +18 -0
- package/dist/ts/input/index.d.ts +4 -0
- package/dist/ts/input/index.ts +4 -0
- package/dist/ts/input/input.d.ts +345 -0
- package/dist/ts/input/input.ts +1277 -0
- package/dist/ts/maskedtextbox/base/index.d.ts +4 -0
- package/dist/ts/maskedtextbox/base/index.ts +4 -0
- package/dist/ts/maskedtextbox/base/mask-base.d.ts +134 -0
- package/dist/ts/maskedtextbox/base/mask-base.ts +1207 -0
- package/dist/ts/maskedtextbox/index.d.ts +5 -0
- package/dist/ts/maskedtextbox/index.ts +5 -0
- package/dist/ts/maskedtextbox/maskedtextbox/index.d.ts +5 -0
- package/dist/ts/maskedtextbox/maskedtextbox/index.ts +5 -0
- package/dist/ts/maskedtextbox/maskedtextbox/maskedtextbox-model.d.ts +167 -0
- package/dist/ts/maskedtextbox/maskedtextbox/maskedtextbox.d.ts +307 -0
- package/dist/ts/maskedtextbox/maskedtextbox/maskedtextbox.ts +709 -0
- package/dist/ts/numerictextbox/index.d.ts +5 -0
- package/dist/ts/numerictextbox/index.ts +5 -0
- package/dist/ts/numerictextbox/numerictextbox-model.d.ts +228 -0
- package/dist/ts/numerictextbox/numerictextbox.d.ts +431 -0
- package/dist/ts/numerictextbox/numerictextbox.ts +1672 -0
- package/dist/ts/otp-input/index.d.ts +5 -0
- package/dist/ts/otp-input/index.ts +5 -0
- package/dist/ts/otp-input/otp-input-model.d.ts +165 -0
- package/dist/ts/otp-input/otp-input.d.ts +365 -0
- package/dist/ts/otp-input/otp-input.ts +924 -0
- package/dist/ts/rating/index.d.ts +5 -0
- package/dist/ts/rating/index.ts +5 -0
- package/dist/ts/rating/rating-model.d.ts +239 -0
- package/dist/ts/rating/rating.d.ts +416 -0
- package/dist/ts/rating/rating.ts +1101 -0
- package/dist/ts/signature/index.d.ts +5 -0
- package/dist/ts/signature/index.ts +5 -0
- package/dist/ts/signature/signature-model.d.ts +131 -0
- package/dist/ts/signature/signature.d.ts +167 -0
- package/dist/ts/signature/signature.ts +266 -0
- package/dist/ts/slider/index.d.ts +5 -0
- package/dist/ts/slider/index.ts +5 -0
- package/dist/ts/slider/slider-model.d.ts +401 -0
- package/dist/ts/slider/slider.d.ts +721 -0
- package/dist/ts/slider/slider.ts +3497 -0
- package/dist/ts/smart-textarea/caret-helper.d.ts +17 -0
- package/dist/ts/smart-textarea/caret-helper.ts +95 -0
- package/dist/ts/smart-textarea/index.d.ts +5 -0
- package/dist/ts/smart-textarea/index.ts +5 -0
- package/dist/ts/smart-textarea/smart-textarea-model.d.ts +44 -0
- package/dist/ts/smart-textarea/smart-textarea.d.ts +80 -0
- package/dist/ts/smart-textarea/smart-textarea.ts +518 -0
- package/dist/ts/speech-to-text/index.d.ts +5 -0
- package/dist/ts/speech-to-text/index.ts +5 -0
- package/dist/ts/speech-to-text/speech-to-text-model.d.ts +270 -0
- package/dist/ts/speech-to-text/speech-to-text.d.ts +487 -0
- package/dist/ts/speech-to-text/speech-to-text.ts +1008 -0
- package/dist/ts/textarea/index.d.ts +5 -0
- package/dist/ts/textarea/index.ts +5 -0
- package/dist/ts/textarea/textarea-model.d.ts +161 -0
- package/dist/ts/textarea/textarea.d.ts +237 -0
- package/dist/ts/textarea/textarea.ts +812 -0
- package/dist/ts/textbox/index.d.ts +5 -0
- package/dist/ts/textbox/index.ts +5 -0
- package/dist/ts/textbox/textbox-model.d.ts +155 -0
- package/dist/ts/textbox/textbox.d.ts +288 -0
- package/dist/ts/textbox/textbox.ts +872 -0
- package/dist/ts/uploader/index.d.ts +5 -0
- package/dist/ts/uploader/index.ts +5 -0
- package/dist/ts/uploader/uploader-model.d.ts +555 -0
- package/dist/ts/uploader/uploader.d.ts +1216 -0
- package/dist/ts/uploader/uploader.ts +4391 -0
- package/package.json +62 -12
- package/src/input/input.js +1 -1
- package/styles/bootstrap5.3-lite.css +3 -3
- package/styles/bootstrap5.3.css +5 -5
- package/styles/input/_layout.scss +0 -1
- package/styles/input/tailwind3.css +0 -1
- package/styles/tailwind-dark-lite.css +3 -3
- package/styles/tailwind-dark.css +5 -5
- package/styles/tailwind-lite.css +3 -3
- package/styles/tailwind.css +5 -5
- package/styles/tailwind3-lite.css +0 -1
- package/styles/tailwind3.css +0 -1
- package/styles/uploader/_bootstrap5.3-definition.scss +1 -1
- package/styles/uploader/_tailwind-definition.scss +1 -1
- package/styles/uploader/bootstrap5.3.css +5 -5
- package/styles/uploader/tailwind-dark.css +5 -5
- package/styles/uploader/tailwind.css +5 -5
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import { Component, Event, Property, EmitType, NotifyPropertyChanges, INotifyPropertyChanged, BaseEventArgs } from '@syncfusion/ej2-base';
|
|
2
|
+
import { isNullOrUndefined, formatUnit, getValue, setValue, addClass, detach } from '@syncfusion/ej2-base';
|
|
3
|
+
import { removeClass , Browser, closest} from '@syncfusion/ej2-base';
|
|
4
|
+
import { Input, InputObject, FloatLabelType } from '../../input/input';
|
|
5
|
+
import { regularExpressions, createMask, applyMask, wireEvents, unwireEvents, unstrippedValue, strippedValue } from '../base/index';
|
|
6
|
+
import { setMaskValue, MaskUndo, setElementValue, bindClearEvent } from '../base/index';
|
|
7
|
+
import { MaskedTextBoxModel } from './maskedtextbox-model';
|
|
8
|
+
|
|
9
|
+
const ROOT: string = 'e-control-wrapper e-mask';
|
|
10
|
+
const INPUT: string = 'e-input';
|
|
11
|
+
const COMPONENT: string = 'e-maskedtextbox';
|
|
12
|
+
const CONTROL: string = 'e-control';
|
|
13
|
+
const MASKINPUT_FOCUS: string = 'e-input-focus';
|
|
14
|
+
const wrapperAttr: string[] = ['title', 'style', 'class'];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The MaskedTextBox allows the user to enter the valid input only based on the provided mask.
|
|
18
|
+
* ```html
|
|
19
|
+
* <input id="mask" type="text" />
|
|
20
|
+
* ```
|
|
21
|
+
* ```typescript
|
|
22
|
+
* <script>
|
|
23
|
+
* var maskObj = new MaskedTextBox({ mask: "(999) 9999-999" });
|
|
24
|
+
* maskObj.appendTo('#mask');
|
|
25
|
+
* </script>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
@NotifyPropertyChanges
|
|
30
|
+
export class MaskedTextBox extends Component<HTMLInputElement> implements INotifyPropertyChanged {
|
|
31
|
+
|
|
32
|
+
/* Internal variables */
|
|
33
|
+
private cloneElement: HTMLElement;
|
|
34
|
+
private promptMask: string;
|
|
35
|
+
private hiddenMask: string;
|
|
36
|
+
private escapeMaskValue: string;
|
|
37
|
+
private regExpCollec: { [key: string]: string };
|
|
38
|
+
private customRegExpCollec: string[];
|
|
39
|
+
private maskedRegExp: string[];
|
|
40
|
+
private inputObj: InputObject;
|
|
41
|
+
private undoCollec: MaskUndo[];
|
|
42
|
+
private redoCollec: MaskUndo[];
|
|
43
|
+
private changeEventArgs: MaskChangeEventArgs;
|
|
44
|
+
private focusEventArgs: MaskFocusEventArgs;
|
|
45
|
+
private blurEventArgs: MaskBlurEventArgs;
|
|
46
|
+
private maskKeyPress: boolean;
|
|
47
|
+
private angularTagName: string;
|
|
48
|
+
private prevValue: string;
|
|
49
|
+
private isFocus: boolean;
|
|
50
|
+
private isInitial: boolean;
|
|
51
|
+
private isIosInvalid: boolean;
|
|
52
|
+
private preEleVal: string;
|
|
53
|
+
private formElement: HTMLElement;
|
|
54
|
+
private initInputValue: string = '';
|
|
55
|
+
private maskOptions: MaskedTextBoxModel;
|
|
56
|
+
private preventChange: boolean = false;
|
|
57
|
+
private isClicked: boolean = false;
|
|
58
|
+
private clearButton: HTMLElement;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Gets or sets the CSS classes to root element of the MaskedTextBox which helps to customize the
|
|
62
|
+
* complete UI styles for the MaskedTextBox component.
|
|
63
|
+
*
|
|
64
|
+
* @default null
|
|
65
|
+
*/
|
|
66
|
+
@Property(null)
|
|
67
|
+
public cssClass: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sets the width of the MaskedTextBox.
|
|
71
|
+
*
|
|
72
|
+
* @default null
|
|
73
|
+
*/
|
|
74
|
+
@Property(null)
|
|
75
|
+
public width: number | string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Gets or sets the string shown as a hint/placeholder when the MaskedTextBox is empty.
|
|
79
|
+
* It acts as a label and floats above the MaskedTextBox based on the
|
|
80
|
+
* <b><a href="#floatlabeltype" target="_blank">floatLabelType.</a></b>
|
|
81
|
+
*
|
|
82
|
+
* @default null
|
|
83
|
+
*/
|
|
84
|
+
@Property(null)
|
|
85
|
+
public placeholder: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The <b><a href="#placeholder" target="_blank">placeholder</a></b> acts as a label
|
|
89
|
+
* and floats above the MaskedTextBox based on the below values.
|
|
90
|
+
* Possible values are:
|
|
91
|
+
* * Never - The floating label will not be enable when the placeholder is available.
|
|
92
|
+
* * Always - The floating label always floats above the MaskedTextBox.
|
|
93
|
+
* * Auto - The floating label floats above the MaskedTextBox after focusing it or when enters the value in it.
|
|
94
|
+
*
|
|
95
|
+
* @default Never
|
|
96
|
+
*/
|
|
97
|
+
@Property('Never')
|
|
98
|
+
public floatLabelType: FloatLabelType;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* You can add the additional html attributes such as disabled, value etc., to the element.
|
|
102
|
+
* If you configured both property and equivalent html attribute then the component considers the property value.
|
|
103
|
+
* {% codeBlock src='maskedtextbox/htmlAttributes/index.md' %}{% endcodeBlock %}
|
|
104
|
+
*
|
|
105
|
+
* @default {}
|
|
106
|
+
*/
|
|
107
|
+
@Property({})
|
|
108
|
+
public htmlAttributes: { [key: string]: string };
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Sets a value that enables or disables the MaskedTextBox component.
|
|
112
|
+
*
|
|
113
|
+
* @default true
|
|
114
|
+
*/
|
|
115
|
+
@Property(true)
|
|
116
|
+
public enabled: boolean;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Specifies the boolean value whether the Masked TextBox allows the user to change the text.
|
|
120
|
+
*
|
|
121
|
+
* @default false
|
|
122
|
+
*/
|
|
123
|
+
@Property(false)
|
|
124
|
+
public readonly: boolean;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Specifies whether to show or hide the clear icon.
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
@Property(false)
|
|
132
|
+
public showClearButton: boolean;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Sets a value that enables or disables the persisting state of the MaskedTextBox after reloading the page.
|
|
136
|
+
* If enabled, the 'value' state will be persisted.
|
|
137
|
+
*
|
|
138
|
+
* @default false
|
|
139
|
+
*/
|
|
140
|
+
@Property(false)
|
|
141
|
+
public enablePersistence: boolean;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Sets a value that masks the MaskedTextBox to allow/validate the user input.
|
|
145
|
+
* * Mask allows [`standard mask elements`](../../maskedtextbox/mask-configuration/#standard-mask-elements)
|
|
146
|
+
* </b>, <b>[`custom characters`](../../maskedtextbox/mask-configuration/#custom-characters)</b> and
|
|
147
|
+
* <b>[`regular expression`](../../maskedtextbox/mask-configuration/#regular-expression)</b> as mask
|
|
148
|
+
* elements.
|
|
149
|
+
* For more information on mask, refer to
|
|
150
|
+
* [mask](../../maskedtextbox/mask-configuration/#standard-mask-elements).
|
|
151
|
+
* * If the mask value is empty, the MaskedTextBox will behave as an input element with text type.
|
|
152
|
+
*
|
|
153
|
+
* {% codeBlock src='maskedtextbox/mask/index.md' %}{% endcodeBlock %}
|
|
154
|
+
*
|
|
155
|
+
* @default null
|
|
156
|
+
*/
|
|
157
|
+
@Property(null)
|
|
158
|
+
public mask: string;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Gets or sets a value that will be shown as a prompting symbol for the masked value.
|
|
162
|
+
* The symbol used to show input positions in the MaskedTextBox.
|
|
163
|
+
* For more information on prompt-character, refer to
|
|
164
|
+
* [prompt-character](../../maskedtextbox/mask-configuration/#prompt-character).
|
|
165
|
+
*
|
|
166
|
+
* @default '_'
|
|
167
|
+
*/
|
|
168
|
+
@Property('_')
|
|
169
|
+
public promptChar: string;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets or sets the value of the MaskedTextBox. It is a raw value of the MaskedTextBox excluding literals
|
|
173
|
+
* and prompt characters. By using `getMaskedValue` property, you can get the value of MaskedTextBox with the masked format.
|
|
174
|
+
* {% codeBlock src='maskedtextbox/value/index.md' %}{% endcodeBlock %}
|
|
175
|
+
*
|
|
176
|
+
* @default null
|
|
177
|
+
*/
|
|
178
|
+
@Property(null)
|
|
179
|
+
public value: string;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Sets the collection of values to be mapped for non-mask elements(literals)
|
|
183
|
+
* which have been set in the mask of MaskedTextBox.
|
|
184
|
+
* In the below example, non-mask elements "P" accepts values
|
|
185
|
+
* "P" , "A" , "p" , "a" and "M" accepts values "M", "m" mentioned in the custom characters collection.
|
|
186
|
+
* > For more information on customCharacters, refer to
|
|
187
|
+
* [customCharacters](../../maskedtextbox/mask-configuration/#custom-characters).
|
|
188
|
+
* {% codeBlock src='maskedtextbox/customCharacters/index.md' %}{% endcodeBlock %}
|
|
189
|
+
*
|
|
190
|
+
* @default null
|
|
191
|
+
*/
|
|
192
|
+
@Property(null)
|
|
193
|
+
public customCharacters: { [x: string]: Object };
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Triggers when the MaskedTextBox component is created.
|
|
197
|
+
*
|
|
198
|
+
* @event created
|
|
199
|
+
*/
|
|
200
|
+
@Event()
|
|
201
|
+
public created: EmitType<Object>;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Triggers when the MaskedTextBox component is destroyed.
|
|
205
|
+
*
|
|
206
|
+
* @event destroyed
|
|
207
|
+
*/
|
|
208
|
+
@Event()
|
|
209
|
+
public destroyed: EmitType<Object>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Triggers when the value of the MaskedTextBox changes.
|
|
213
|
+
*
|
|
214
|
+
* @event change
|
|
215
|
+
*/
|
|
216
|
+
@Event()
|
|
217
|
+
public change: EmitType <MaskChangeEventArgs>;
|
|
218
|
+
/**
|
|
219
|
+
* Triggers when the MaskedTextBox got focus in.
|
|
220
|
+
*
|
|
221
|
+
* @event focus
|
|
222
|
+
*/
|
|
223
|
+
@Event()
|
|
224
|
+
public focus: EmitType<MaskFocusEventArgs>;
|
|
225
|
+
/**
|
|
226
|
+
* Triggers when the MaskedTextBox got focus out.
|
|
227
|
+
*
|
|
228
|
+
* @event blur
|
|
229
|
+
*/
|
|
230
|
+
@Event()
|
|
231
|
+
public blur: EmitType<MaskBlurEventArgs>;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @param {MaskedTextBoxModel} options - Specifies the MaskedTextBox model.
|
|
236
|
+
* @param {string | HTMLElement | HTMLInputElement} element - Specifies the element to render as component.
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
public constructor(options?: MaskedTextBoxModel, element?: string | HTMLElement | HTMLInputElement) {
|
|
240
|
+
super(options, <HTMLInputElement | string>element);
|
|
241
|
+
this.maskOptions = options;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Gets the component name.
|
|
246
|
+
*
|
|
247
|
+
* @returns {string} Returns the component name.
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
250
|
+
protected getModuleName(): string {
|
|
251
|
+
return 'maskedtextbox';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Initializes the event handler
|
|
256
|
+
*
|
|
257
|
+
* @returns {void}
|
|
258
|
+
* @private
|
|
259
|
+
*/
|
|
260
|
+
protected preRender(): void {
|
|
261
|
+
this.promptMask = '';
|
|
262
|
+
this.hiddenMask = '';
|
|
263
|
+
this.escapeMaskValue = '';
|
|
264
|
+
this.regExpCollec = regularExpressions;
|
|
265
|
+
this.customRegExpCollec = [];
|
|
266
|
+
this.maskedRegExp = [];
|
|
267
|
+
this.undoCollec = [];
|
|
268
|
+
this.redoCollec = [];
|
|
269
|
+
this.changeEventArgs = {};
|
|
270
|
+
this.focusEventArgs = {};
|
|
271
|
+
this.blurEventArgs = {};
|
|
272
|
+
this.maskKeyPress = false;
|
|
273
|
+
this.isFocus = false;
|
|
274
|
+
this.isInitial = false;
|
|
275
|
+
this.isIosInvalid = false;
|
|
276
|
+
const ejInstance: Object = getValue('ej2_instances', this.element);
|
|
277
|
+
this.cloneElement = <HTMLElement>this.element.cloneNode(true);
|
|
278
|
+
removeClass([this.cloneElement], [CONTROL, COMPONENT, 'e-lib']);
|
|
279
|
+
this.angularTagName = null;
|
|
280
|
+
this.formElement = <HTMLFormElement>closest(this.element, 'form');
|
|
281
|
+
if (this.element.tagName === 'EJS-MASKEDTEXTBOX') {
|
|
282
|
+
this.angularTagName = this.element.tagName;
|
|
283
|
+
const input: HTMLElement = this.createElement('input');
|
|
284
|
+
for (let i: number = 0; i < this.element.attributes.length; i++) {
|
|
285
|
+
input.setAttribute(this.element.attributes[i as number].nodeName, this.element.attributes[i as number].nodeValue);
|
|
286
|
+
input.innerHTML = this.element.innerHTML;
|
|
287
|
+
}
|
|
288
|
+
if (this.element.hasAttribute('id')) {
|
|
289
|
+
this.element.removeAttribute('id');
|
|
290
|
+
}
|
|
291
|
+
if (this.element.hasAttribute('name')) {
|
|
292
|
+
this.element.removeAttribute('name');
|
|
293
|
+
}
|
|
294
|
+
this.element.classList.remove('e-control', 'e-maskedtextbox');
|
|
295
|
+
this.element.classList.add('e-mask-container');
|
|
296
|
+
this.element.appendChild(input);
|
|
297
|
+
this.element = <HTMLInputElement>input;
|
|
298
|
+
setValue('ej2_instances', ejInstance, this.element);
|
|
299
|
+
}
|
|
300
|
+
this.updateHTMLAttrToElement();
|
|
301
|
+
this.checkHtmlAttributes(false);
|
|
302
|
+
if (this.formElement) {
|
|
303
|
+
this.initInputValue = this.value;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/* eslint-disable valid-jsdoc, jsdoc/require-returns-description */
|
|
307
|
+
/**
|
|
308
|
+
* Gets the properties to be maintained in the persisted state.
|
|
309
|
+
*
|
|
310
|
+
* @returns {string}
|
|
311
|
+
*/
|
|
312
|
+
public getPersistData(): string {
|
|
313
|
+
const keyEntity: string[] = ['value'];
|
|
314
|
+
return this.addOnPersist(keyEntity);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Initializes the component rendering.
|
|
319
|
+
*
|
|
320
|
+
* @returns {void}
|
|
321
|
+
* @private
|
|
322
|
+
*/
|
|
323
|
+
public render(): void {
|
|
324
|
+
if (this.element.tagName.toLowerCase() === 'input') {
|
|
325
|
+
if (this.floatLabelType === 'Never') {
|
|
326
|
+
addClass([this.element], INPUT);
|
|
327
|
+
}
|
|
328
|
+
this.createWrapper();
|
|
329
|
+
this.updateHTMLAttrToWrapper();
|
|
330
|
+
if (this.element.name === '') {
|
|
331
|
+
this.element.setAttribute('name', this.element.id);
|
|
332
|
+
}
|
|
333
|
+
this.isInitial = true;
|
|
334
|
+
this.resetMaskedTextBox();
|
|
335
|
+
this.isInitial = false;
|
|
336
|
+
this.setMaskPlaceholder(true, false);
|
|
337
|
+
this.setWidth(this.width);
|
|
338
|
+
this.preEleVal = this.element.value;
|
|
339
|
+
if (!Browser.isDevice && (Browser.info.version === '11.0' || Browser.info.name === 'edge')) {
|
|
340
|
+
this.element.blur();
|
|
341
|
+
}
|
|
342
|
+
if (Browser.isDevice && Browser.isIos) {
|
|
343
|
+
this.element.blur();
|
|
344
|
+
}
|
|
345
|
+
if (this.element.getAttribute('value') || this.value) {
|
|
346
|
+
this.element.setAttribute('value', this.element.value);
|
|
347
|
+
}
|
|
348
|
+
if (!isNullOrUndefined(closest(this.element, 'fieldset') as HTMLFieldSetElement) && (closest(this.element, 'fieldset') as HTMLFieldSetElement).disabled) {
|
|
349
|
+
this.enabled = false;
|
|
350
|
+
}
|
|
351
|
+
if (!this.element.hasAttribute('aria-labelledby') && !this.element.hasAttribute('placeholder') && !this.element.hasAttribute('aria-label')) {
|
|
352
|
+
this.element.setAttribute('aria-label', 'maskedtextbox');
|
|
353
|
+
}
|
|
354
|
+
this.renderComplete();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
private updateHTMLAttrToElement(): void {
|
|
358
|
+
if ( !isNullOrUndefined(this.htmlAttributes)) {
|
|
359
|
+
for (const key of Object.keys(this.htmlAttributes)) {
|
|
360
|
+
if (wrapperAttr.indexOf(key) < 0 ) {
|
|
361
|
+
this.element.setAttribute(key, this.htmlAttributes[`${key}`]);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
private updateCssClass(newClass : string, oldClass : string) : void {
|
|
367
|
+
Input.setCssClass(this.getValidClassList(newClass), [this.inputObj.container], this.getValidClassList(oldClass));
|
|
368
|
+
}
|
|
369
|
+
private getValidClassList(maskClassName: string): string {
|
|
370
|
+
let result: string = maskClassName;
|
|
371
|
+
if (!isNullOrUndefined(maskClassName) && maskClassName !== '') {
|
|
372
|
+
result = (maskClassName.replace(/\s+/g, ' ')).trim();
|
|
373
|
+
}
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
private updateHTMLAttrToWrapper(): void {
|
|
377
|
+
if ( !isNullOrUndefined(this.htmlAttributes)) {
|
|
378
|
+
for (const key of Object.keys(this.htmlAttributes)) {
|
|
379
|
+
if (wrapperAttr.indexOf(key) > -1 ) {
|
|
380
|
+
if (key === 'class') {
|
|
381
|
+
const updatedClassValues : string = (this.htmlAttributes[`${key}`].replace(/\s+/g, ' ')).trim();
|
|
382
|
+
if (updatedClassValues !== '') {
|
|
383
|
+
addClass([this.inputObj.container], updatedClassValues.split(' '));
|
|
384
|
+
}
|
|
385
|
+
} else if (key === 'style') {
|
|
386
|
+
let maskStyle: string = this.inputObj.container.getAttribute(key);
|
|
387
|
+
maskStyle = !isNullOrUndefined(maskStyle) ? (maskStyle + this.htmlAttributes[`${key}`]) :
|
|
388
|
+
this.htmlAttributes[`${key}`];
|
|
389
|
+
this.inputObj.container.setAttribute(key, maskStyle);
|
|
390
|
+
} else {
|
|
391
|
+
this.inputObj.container.setAttribute(key, this.htmlAttributes[`${key}`]);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
private resetMaskedTextBox(): void {
|
|
399
|
+
this.promptMask = '';
|
|
400
|
+
this.hiddenMask = '';
|
|
401
|
+
this.escapeMaskValue = '';
|
|
402
|
+
this.customRegExpCollec = [];
|
|
403
|
+
this.undoCollec = [];
|
|
404
|
+
this.redoCollec = [];
|
|
405
|
+
if (this.promptChar && this.promptChar.length > 1) {
|
|
406
|
+
this.promptChar = this.promptChar[0];
|
|
407
|
+
}
|
|
408
|
+
createMask.call(this);
|
|
409
|
+
applyMask.call(this);
|
|
410
|
+
if (this.mask === null || this.mask === '' && this.value !== undefined ) {
|
|
411
|
+
setElementValue.call(this, this.value);
|
|
412
|
+
}
|
|
413
|
+
const val: string = strippedValue.call(this, this.element);
|
|
414
|
+
this.prevValue = val;
|
|
415
|
+
this.value = val;
|
|
416
|
+
if (!this.isInitial) {
|
|
417
|
+
unwireEvents.call(this);
|
|
418
|
+
}
|
|
419
|
+
wireEvents.call(this);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
private setMaskPlaceholder(setVal: boolean, dynamicPlaceholder: boolean): void {
|
|
423
|
+
if (dynamicPlaceholder || this.placeholder) {
|
|
424
|
+
Input.setPlaceholder(this.placeholder, this.element);
|
|
425
|
+
if ((this.element.value === this.promptMask && setVal && this.floatLabelType !== 'Always') ||
|
|
426
|
+
this.element.value === this.promptMask && this.floatLabelType === 'Never') {
|
|
427
|
+
setElementValue.call(this, '');
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
private setWidth(width: string | number): void {
|
|
433
|
+
if (!isNullOrUndefined(width)) {
|
|
434
|
+
if (typeof width === 'number') {
|
|
435
|
+
this.inputObj.container.style.width = formatUnit(width);
|
|
436
|
+
this.element.style.width = formatUnit(width);
|
|
437
|
+
} else if (typeof width === 'string') {
|
|
438
|
+
const elementWidth: string = (width.match(/px|%|em/)) ? <string>(width) : <string>(formatUnit(width));
|
|
439
|
+
this.inputObj.container.style.width = elementWidth;
|
|
440
|
+
this.element.style.width = elementWidth;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
private checkHtmlAttributes(isDynamic: boolean): void {
|
|
445
|
+
const attributes: string[] = isDynamic ? isNullOrUndefined(this.htmlAttributes) ? [] : Object.keys(this.htmlAttributes)
|
|
446
|
+
: ['placeholder', 'disabled', 'value', 'readonly'];
|
|
447
|
+
for (const key of attributes) {
|
|
448
|
+
if (!isNullOrUndefined(this.element.getAttribute(key))) {
|
|
449
|
+
switch (key) {
|
|
450
|
+
case 'placeholder':
|
|
451
|
+
if (( isNullOrUndefined(this.maskOptions) || (this.maskOptions['placeholder'] === undefined)) || isDynamic) {
|
|
452
|
+
this.setProperties({placeholder: this.element.placeholder}, !isDynamic);
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
case 'disabled':
|
|
456
|
+
if (( isNullOrUndefined(this.maskOptions) || (this.maskOptions['enabled'] === undefined)) || isDynamic) {
|
|
457
|
+
const isEnabled: boolean = this.element.getAttribute(key) === 'disabled' || this.element.getAttribute(key) === '' ||
|
|
458
|
+
this.element.getAttribute(key) === 'true' ? false : true;
|
|
459
|
+
this.setProperties({ enabled: isEnabled }, !isDynamic);
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
case 'value':
|
|
463
|
+
if (( isNullOrUndefined(this.maskOptions) || (this.maskOptions['value'] === undefined)) || isDynamic) {
|
|
464
|
+
this.setProperties({value: this.element.value}, !isDynamic);
|
|
465
|
+
}
|
|
466
|
+
break;
|
|
467
|
+
case 'readonly':
|
|
468
|
+
if (( isNullOrUndefined(this.maskOptions) || (this.maskOptions['readonly'] === undefined)) || isDynamic) {
|
|
469
|
+
const isReadonly: boolean = this.element.getAttribute(key) === 'readonly' || this.element.getAttribute(key) === ''
|
|
470
|
+
|| this.element.getAttribute(key) === 'true' ? true : false;
|
|
471
|
+
this.setProperties({readonly: isReadonly}, !isDynamic);
|
|
472
|
+
}
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
private createWrapper(): void {
|
|
480
|
+
let updatedCssClassValues: string = this.cssClass;
|
|
481
|
+
if (!isNullOrUndefined(this.cssClass) && this.cssClass !== '') {
|
|
482
|
+
updatedCssClassValues = this.getValidClassList(this.cssClass);
|
|
483
|
+
}
|
|
484
|
+
this.inputObj = Input.createInput(
|
|
485
|
+
{
|
|
486
|
+
element: this.element,
|
|
487
|
+
floatLabelType: this.floatLabelType,
|
|
488
|
+
properties: {
|
|
489
|
+
enableRtl: this.enableRtl,
|
|
490
|
+
cssClass: updatedCssClassValues,
|
|
491
|
+
enabled: this.enabled,
|
|
492
|
+
readonly: this.readonly,
|
|
493
|
+
placeholder: this.placeholder,
|
|
494
|
+
showClearButton: this.showClearButton
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
this.createElement);
|
|
498
|
+
this.inputObj.container.setAttribute('class', ROOT + ' ' + this.inputObj.container.getAttribute('class'));
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Calls internally if any of the property value is changed.
|
|
503
|
+
*
|
|
504
|
+
* @param {MaskedTextBoxModel} newProp - Returns the dynamic property value of the component.
|
|
505
|
+
* @param {MaskedTextBoxModel} oldProp - Returns the previous property value of the component.
|
|
506
|
+
* @returns {void}
|
|
507
|
+
* @hidden
|
|
508
|
+
*/
|
|
509
|
+
public onPropertyChanged(newProp: MaskedTextBoxModel, oldProp: MaskedTextBoxModel): void {
|
|
510
|
+
for (const prop of Object.keys(newProp)) {
|
|
511
|
+
switch (prop) {
|
|
512
|
+
case 'value':
|
|
513
|
+
setMaskValue.call(this, this.value);
|
|
514
|
+
if (this.placeholder && !this.isFocus) {
|
|
515
|
+
this.setMaskPlaceholder(false, false);
|
|
516
|
+
}
|
|
517
|
+
if (this.value === '' && oldProp.value != null) {
|
|
518
|
+
this.element.selectionStart = 0;
|
|
519
|
+
this.element.selectionEnd = 0;
|
|
520
|
+
}
|
|
521
|
+
break;
|
|
522
|
+
case 'placeholder':
|
|
523
|
+
this.setMaskPlaceholder(true, true);
|
|
524
|
+
break;
|
|
525
|
+
case 'width':
|
|
526
|
+
this.setWidth(newProp.width);
|
|
527
|
+
Input.calculateWidth(this.element, this.inputObj.container);
|
|
528
|
+
break;
|
|
529
|
+
case 'cssClass':
|
|
530
|
+
this.updateCssClass(newProp.cssClass, oldProp.cssClass);
|
|
531
|
+
break;
|
|
532
|
+
case 'enabled':
|
|
533
|
+
Input.setEnabled(newProp.enabled, this.element, this.floatLabelType, this.inputObj.container);
|
|
534
|
+
break;
|
|
535
|
+
case 'readonly':
|
|
536
|
+
Input.setReadonly(newProp.readonly, this.element);
|
|
537
|
+
break;
|
|
538
|
+
case 'enableRtl':
|
|
539
|
+
Input.setEnableRtl(newProp.enableRtl, [this.inputObj.container]);
|
|
540
|
+
break;
|
|
541
|
+
case 'customCharacters':
|
|
542
|
+
this.customCharacters = newProp.customCharacters;
|
|
543
|
+
this.resetMaskedTextBox();
|
|
544
|
+
break;
|
|
545
|
+
case 'showClearButton':
|
|
546
|
+
Input.setClearButton(newProp.showClearButton, this.element, this.inputObj, undefined, this.createElement);
|
|
547
|
+
bindClearEvent.call(this);
|
|
548
|
+
break;
|
|
549
|
+
case 'floatLabelType':
|
|
550
|
+
this.floatLabelType = newProp.floatLabelType;
|
|
551
|
+
Input.removeFloating(this.inputObj);
|
|
552
|
+
Input.addFloating(this.element, this.floatLabelType, this.placeholder, this.createElement);
|
|
553
|
+
break;
|
|
554
|
+
case 'htmlAttributes':
|
|
555
|
+
this.updateHTMLAttrToElement();
|
|
556
|
+
this.updateHTMLAttrToWrapper();
|
|
557
|
+
this.checkHtmlAttributes(true);
|
|
558
|
+
break;
|
|
559
|
+
case 'mask': {
|
|
560
|
+
const strippedValue: string = this.value;
|
|
561
|
+
this.mask = newProp.mask;
|
|
562
|
+
this.maskedRegExp = [];
|
|
563
|
+
this.updateValue(strippedValue);
|
|
564
|
+
}
|
|
565
|
+
break;
|
|
566
|
+
case 'promptChar': {
|
|
567
|
+
if (newProp.promptChar.length > 1) {
|
|
568
|
+
newProp.promptChar = newProp.promptChar[0];
|
|
569
|
+
}
|
|
570
|
+
if (newProp.promptChar) {
|
|
571
|
+
this.promptChar = newProp.promptChar;
|
|
572
|
+
} else {
|
|
573
|
+
this.promptChar = '_';
|
|
574
|
+
}
|
|
575
|
+
/* eslint-disable-next-line security/detect-non-literal-regexp */
|
|
576
|
+
let value: string = this.element.value.replace(new RegExp('[' + oldProp.promptChar + ']', 'g'), this.promptChar);
|
|
577
|
+
if (this.promptMask === this.element.value) {
|
|
578
|
+
/* eslint-disable-next-line security/detect-non-literal-regexp */
|
|
579
|
+
value = this.promptMask.replace(new RegExp('[' + oldProp.promptChar + ']', 'g'), this.promptChar);
|
|
580
|
+
}
|
|
581
|
+
/* eslint-disable-next-line security/detect-non-literal-regexp */
|
|
582
|
+
this.promptMask = this.promptMask.replace(new RegExp('[' + oldProp.promptChar + ']', 'g'), this.promptChar);
|
|
583
|
+
this.undoCollec = this.redoCollec = [];
|
|
584
|
+
setElementValue.call(this, value);
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
this.preventChange = this.isAngular && this.preventChange ? !this.preventChange : this.preventChange;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private updateValue(strippedVal: string): void {
|
|
593
|
+
this.resetMaskedTextBox();
|
|
594
|
+
setMaskValue.call(this, strippedVal);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Gets the value of the MaskedTextBox with the masked format.
|
|
599
|
+
* By using `value` property, you can get the raw value of maskedtextbox without literals and prompt characters.
|
|
600
|
+
*
|
|
601
|
+
* @returns {string} Returns the value with the masked format.
|
|
602
|
+
*/
|
|
603
|
+
public getMaskedValue(): string {
|
|
604
|
+
return unstrippedValue.call(this, this.element);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Sets the focus to widget for interaction.
|
|
609
|
+
*
|
|
610
|
+
* @returns {void}
|
|
611
|
+
*/
|
|
612
|
+
public focusIn(): void {
|
|
613
|
+
if (document.activeElement !== this.element && this.enabled) {
|
|
614
|
+
this.isFocus = true;
|
|
615
|
+
this.element.focus();
|
|
616
|
+
addClass([this.inputObj.container], [MASKINPUT_FOCUS]);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Remove the focus from widget, if the widget is in focus state.
|
|
622
|
+
*
|
|
623
|
+
* @returns {void}
|
|
624
|
+
*/
|
|
625
|
+
public focusOut(): void {
|
|
626
|
+
if (document.activeElement === this.element && this.enabled) {
|
|
627
|
+
this.isFocus = false;
|
|
628
|
+
this.element.blur();
|
|
629
|
+
removeClass([this.inputObj.container], [MASKINPUT_FOCUS]);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Removes the component from the DOM and detaches all its related event handlers.
|
|
635
|
+
* Also it maintains the initial input element from the DOM.
|
|
636
|
+
*
|
|
637
|
+
* @method destroy
|
|
638
|
+
* @returns {void}
|
|
639
|
+
*/
|
|
640
|
+
public destroy(): void {
|
|
641
|
+
unwireEvents.call(this);
|
|
642
|
+
if (this.showClearButton) {
|
|
643
|
+
this.clearButton = document.getElementsByClassName('e-clear-icon')[0] as HTMLElement;
|
|
644
|
+
}
|
|
645
|
+
const attrArray: string[] = ['aria-labelledby', 'role', 'autocomplete', 'aria-readonly',
|
|
646
|
+
'aria-disabled', 'autocapitalize', 'spellcheck', 'aria-autocomplete', 'aria-live', 'aria-invalid'];
|
|
647
|
+
for (let i: number = 0; i < attrArray.length; i++) {
|
|
648
|
+
this.element.removeAttribute(attrArray[i as number]);
|
|
649
|
+
}
|
|
650
|
+
this.element.classList.remove('e-input');
|
|
651
|
+
if (this.inputObj)
|
|
652
|
+
{
|
|
653
|
+
this.inputObj.container.insertAdjacentElement('afterend', this.element);
|
|
654
|
+
detach(this.inputObj.container);
|
|
655
|
+
}
|
|
656
|
+
this.blurEventArgs = null;
|
|
657
|
+
Input.destroy({
|
|
658
|
+
element: this.element,
|
|
659
|
+
floatLabelType: this.floatLabelType,
|
|
660
|
+
properties: this.properties
|
|
661
|
+
}, this.clearButton);
|
|
662
|
+
this.changeEventArgs = null;
|
|
663
|
+
this.inputObj = null;
|
|
664
|
+
super.destroy();
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
export interface MaskChangeEventArgs extends BaseEventArgs {
|
|
669
|
+
/** Returns the value of the MaskedTextBox with the masked format. */
|
|
670
|
+
maskedValue?: string
|
|
671
|
+
/** Returns the raw value of MaskedTextBox by removing the prompt characters and literals(non-mask elements)
|
|
672
|
+
* which have been set in the mask of MaskedTextBox.
|
|
673
|
+
*/
|
|
674
|
+
value?: string
|
|
675
|
+
/** Returns true when the value of MaskedTextBox is changed by user interaction. Otherwise, it returns false.
|
|
676
|
+
*
|
|
677
|
+
* @private
|
|
678
|
+
*/
|
|
679
|
+
isInteraction?: boolean
|
|
680
|
+
/** Returns true when the value of MaskedTextBox is changed by user interaction. Otherwise, it returns false */
|
|
681
|
+
isInteracted?: boolean
|
|
682
|
+
/** Returns the original event arguments. */
|
|
683
|
+
event?: Event
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
export interface MaskFocusEventArgs extends BaseEventArgs {
|
|
687
|
+
/** Returns selectionStart value as zero by default */
|
|
688
|
+
selectionStart?: number
|
|
689
|
+
/** Returns selectionEnd value depends on mask length */
|
|
690
|
+
selectionEnd?: number
|
|
691
|
+
/** Returns the original event arguments. */
|
|
692
|
+
event?: MouseEvent | FocusEvent | TouchEvent | KeyboardEvent
|
|
693
|
+
/** Returns the value of MaskedTextBox. */
|
|
694
|
+
value?: string
|
|
695
|
+
/** Returns the maskedValue of MaskedTextBox. */
|
|
696
|
+
maskedValue?: string
|
|
697
|
+
/** Returns the MaskedTextBox container element */
|
|
698
|
+
container?: HTMLElement
|
|
699
|
+
}
|
|
700
|
+
export interface MaskBlurEventArgs extends BaseEventArgs {
|
|
701
|
+
/** Returns the original event arguments. */
|
|
702
|
+
event?: MouseEvent | FocusEvent | TouchEvent | KeyboardEvent
|
|
703
|
+
/** Returns the value of MaskedTextBox. */
|
|
704
|
+
value?: string
|
|
705
|
+
/** Returns the maskedValue of MaskedTextBox. */
|
|
706
|
+
maskedValue?: string
|
|
707
|
+
/** Returns the MaskedTextBox container element */
|
|
708
|
+
container?: HTMLElement
|
|
709
|
+
}
|