@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,872 @@
|
|
|
1
|
+
import { Component, Property, Event, EmitType, EventHandler, L10n, setValue, getValue, isNullOrUndefined, Browser } from '@syncfusion/ej2-base';
|
|
2
|
+
import { NotifyPropertyChanges, INotifyPropertyChanged, detach, Internationalization, getUniqueID, closest } from '@syncfusion/ej2-base';
|
|
3
|
+
import { addClass, removeClass } from '@syncfusion/ej2-base';
|
|
4
|
+
import { FloatLabelType, Input, InputObject, containerAttributes, TEXTBOX_FOCUS } from '../input/input';
|
|
5
|
+
import { TextBoxModel} from './textbox-model';
|
|
6
|
+
|
|
7
|
+
const HIDE_CLEAR: string = 'e-clear-icon-hide';
|
|
8
|
+
|
|
9
|
+
export interface FocusInEventArgs {
|
|
10
|
+
/** Returns the TextBox container element */
|
|
11
|
+
container?: HTMLElement
|
|
12
|
+
/** Returns the event parameters from TextBox. */
|
|
13
|
+
event?: Event
|
|
14
|
+
/** Returns the entered value of the TextBox. */
|
|
15
|
+
value?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface FocusOutEventArgs {
|
|
19
|
+
/** Returns the TextBox container element */
|
|
20
|
+
container?: HTMLElement
|
|
21
|
+
/** Returns the event parameters from TextBox. */
|
|
22
|
+
event?: Event
|
|
23
|
+
/** Returns the entered value of the TextBox. */
|
|
24
|
+
value?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ChangedEventArgs extends FocusInEventArgs {
|
|
28
|
+
/** Returns the previously entered value of the TextBox. */
|
|
29
|
+
previousValue?: string
|
|
30
|
+
/** DEPRECATED-Returns the original event. */
|
|
31
|
+
isInteraction?: boolean
|
|
32
|
+
/** Returns the original event. */
|
|
33
|
+
isInteracted?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface InputEventArgs extends FocusInEventArgs {
|
|
37
|
+
/** Returns the previously updated value of the TextBox. */
|
|
38
|
+
previousValue?: string
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents the TextBox component that allows the user to enter the values based on it's type.
|
|
42
|
+
* ```html
|
|
43
|
+
* <input name='images' id='textbox'/>
|
|
44
|
+
* ```
|
|
45
|
+
* ```typescript
|
|
46
|
+
* <script>
|
|
47
|
+
* var textboxObj = new TextBox();
|
|
48
|
+
* textboxObj.appendTo('#textbox');
|
|
49
|
+
* </script>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
@NotifyPropertyChanges
|
|
54
|
+
export class TextBox extends Component<HTMLInputElement | HTMLTextAreaElement> implements INotifyPropertyChanged {
|
|
55
|
+
|
|
56
|
+
private textboxWrapper: InputObject;
|
|
57
|
+
private l10n: L10n;
|
|
58
|
+
private previousValue: string = null;
|
|
59
|
+
private cloneElement: HTMLInputElement;
|
|
60
|
+
private globalize: Internationalization;
|
|
61
|
+
private preventChange: boolean;
|
|
62
|
+
private isHiddenInput: boolean = false;
|
|
63
|
+
private textarea: HTMLTextAreaElement;
|
|
64
|
+
private respectiveElement: HTMLInputElement | HTMLTextAreaElement;
|
|
65
|
+
private isForm: boolean = false;
|
|
66
|
+
private formElement: HTMLElement;
|
|
67
|
+
private initialValue: string;
|
|
68
|
+
private textboxOptions: TextBoxModel;
|
|
69
|
+
private inputPreviousValue: string = null;
|
|
70
|
+
private clearButton: HTMLElement;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Specifies the behavior of the TextBox such as text, password, email, etc.
|
|
74
|
+
*
|
|
75
|
+
* @default 'text'
|
|
76
|
+
*/
|
|
77
|
+
@Property('text')
|
|
78
|
+
public type: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Specifies the boolean value whether the TextBox allows user to change the text.
|
|
82
|
+
*
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
@Property(false)
|
|
86
|
+
public readonly: boolean;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Sets the content of the TextBox.
|
|
90
|
+
*
|
|
91
|
+
* @default null
|
|
92
|
+
*/
|
|
93
|
+
@Property(null)
|
|
94
|
+
public value: string;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Specifies the floating label behavior of the TextBox that the placeholder text floats above the TextBox based on the below values.
|
|
98
|
+
* Possible values are:
|
|
99
|
+
* * `Never` - The placeholder text should not be float ever.
|
|
100
|
+
* * `Always` - The placeholder text floats above the TextBox always.
|
|
101
|
+
* * `Auto` - The placeholder text floats above the TextBox while focusing or enter a value in Textbox.
|
|
102
|
+
*
|
|
103
|
+
* @default Never
|
|
104
|
+
*/
|
|
105
|
+
@Property('Never')
|
|
106
|
+
public floatLabelType: FloatLabelType;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Specifies the CSS class value that is appended to wrapper of Textbox.
|
|
110
|
+
*
|
|
111
|
+
* @default ''
|
|
112
|
+
*/
|
|
113
|
+
@Property('')
|
|
114
|
+
public cssClass: string;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Specifies the text that is shown as a hint/placeholder until the user focus or enter a value in Textbox.
|
|
118
|
+
* The property is depending on the floatLabelType property.
|
|
119
|
+
*
|
|
120
|
+
* @default null
|
|
121
|
+
*/
|
|
122
|
+
@Property(null)
|
|
123
|
+
public placeholder: string;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Specifies whether the browser is allow to automatically enter or select a value for the textbox.
|
|
127
|
+
* By default, autocomplete is enabled for textbox.
|
|
128
|
+
* Possible values are:
|
|
129
|
+
* `on` - Specifies that autocomplete is enabled.
|
|
130
|
+
* `off` - Specifies that autocomplete is disabled.
|
|
131
|
+
*
|
|
132
|
+
* @default 'on'
|
|
133
|
+
*/
|
|
134
|
+
@Property('on')
|
|
135
|
+
public autocomplete: string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* You can add the additional html attributes such as disabled, value etc., to the element.
|
|
139
|
+
* If you configured both property and equivalent html attribute then the component considers the property value.
|
|
140
|
+
* {% codeBlock src='textbox/htmlAttributes/index.md' %}{% endcodeBlock %}
|
|
141
|
+
*
|
|
142
|
+
* @default {}
|
|
143
|
+
*/
|
|
144
|
+
@Property({})
|
|
145
|
+
public htmlAttributes: { [key: string]: string };
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Specifies a boolean value that enable or disable the multiline on the TextBox.
|
|
149
|
+
* The TextBox changes from single line to multiline when enable this multiline mode.
|
|
150
|
+
*
|
|
151
|
+
* @default false
|
|
152
|
+
*/
|
|
153
|
+
@Property(false)
|
|
154
|
+
public multiline: boolean;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Specifies a Boolean value that indicates whether the TextBox allow user to interact with it.
|
|
158
|
+
*
|
|
159
|
+
* @default true
|
|
160
|
+
*/
|
|
161
|
+
@Property(true)
|
|
162
|
+
public enabled: boolean;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Specifies a Boolean value that indicates whether the clear button is displayed in Textbox.
|
|
166
|
+
*
|
|
167
|
+
* @default false
|
|
168
|
+
*/
|
|
169
|
+
@Property(false)
|
|
170
|
+
public showClearButton: boolean;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Enable or disable persisting TextBox state between page reloads. If enabled, the `value` state will be persisted.
|
|
174
|
+
*
|
|
175
|
+
* @default false
|
|
176
|
+
*/
|
|
177
|
+
@Property(false)
|
|
178
|
+
public enablePersistence: boolean;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Specifies the width of the Textbox component.
|
|
182
|
+
*
|
|
183
|
+
* @default null
|
|
184
|
+
*/
|
|
185
|
+
@Property(null)
|
|
186
|
+
public width: number | string;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Triggers when the TextBox component is created.
|
|
190
|
+
*
|
|
191
|
+
* @event created
|
|
192
|
+
*/
|
|
193
|
+
@Event()
|
|
194
|
+
public created: EmitType<Object>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Triggers when the TextBox component is destroyed.
|
|
198
|
+
*
|
|
199
|
+
* @event destroyed
|
|
200
|
+
*/
|
|
201
|
+
@Event()
|
|
202
|
+
public destroyed: EmitType<Object>;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Triggers when the content of TextBox has changed and gets focus-out.
|
|
206
|
+
*
|
|
207
|
+
* @event change
|
|
208
|
+
*/
|
|
209
|
+
@Event()
|
|
210
|
+
public change: EmitType<ChangedEventArgs>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Triggers when the TextBox has focus-out.
|
|
214
|
+
*
|
|
215
|
+
* @event blur
|
|
216
|
+
*/
|
|
217
|
+
@Event()
|
|
218
|
+
public blur: EmitType<FocusOutEventArgs>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Triggers when the TextBox gets focus.
|
|
222
|
+
*
|
|
223
|
+
* @event focus
|
|
224
|
+
*/
|
|
225
|
+
@Event()
|
|
226
|
+
public focus: EmitType<FocusInEventArgs>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Triggers each time when the value of TextBox has changed.
|
|
230
|
+
*
|
|
231
|
+
* @event input
|
|
232
|
+
*/
|
|
233
|
+
@Event()
|
|
234
|
+
public input: EmitType<InputEventArgs>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
*
|
|
238
|
+
* @param {TextBoxModel} options - Specifies the TextBox model.
|
|
239
|
+
* @param {string | HTMLInputElement | HTMLTextAreaElement} element - Specifies the element to render as component.
|
|
240
|
+
* @private
|
|
241
|
+
*/
|
|
242
|
+
public constructor(options?: TextBoxModel, element?: string | HTMLInputElement | HTMLTextAreaElement ) {
|
|
243
|
+
super(options, <string | HTMLInputElement | HTMLTextAreaElement> element);
|
|
244
|
+
this.textboxOptions = options;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Calls internally if any of the property value is changed.
|
|
249
|
+
*
|
|
250
|
+
* @param {TextBoxModel} newProp - Returns the dynamic property value of the component.
|
|
251
|
+
* @param {TextBoxModel} oldProp - Returns the previous property value of the component.
|
|
252
|
+
* @returns {void}
|
|
253
|
+
* @private
|
|
254
|
+
*/
|
|
255
|
+
public onPropertyChanged(newProp: TextBoxModel, oldProp: TextBoxModel): void {
|
|
256
|
+
for (const prop of Object.keys(newProp)) {
|
|
257
|
+
switch (prop) {
|
|
258
|
+
case 'floatLabelType':
|
|
259
|
+
Input.removeFloating(this.textboxWrapper);
|
|
260
|
+
Input.addFloating(this.respectiveElement, this.floatLabelType, this.placeholder);
|
|
261
|
+
break;
|
|
262
|
+
case 'enabled':
|
|
263
|
+
Input.setEnabled(this.enabled, this.respectiveElement, this.floatLabelType, this.textboxWrapper.container);
|
|
264
|
+
this.bindClearEvent();
|
|
265
|
+
break;
|
|
266
|
+
case 'width':
|
|
267
|
+
Input.setWidth(newProp.width, this.textboxWrapper.container);
|
|
268
|
+
break;
|
|
269
|
+
case 'value': {
|
|
270
|
+
const prevOnChange: boolean = this.isProtectedOnChange;
|
|
271
|
+
this.isProtectedOnChange = true;
|
|
272
|
+
if (!Input.isBlank(this.value)) {
|
|
273
|
+
this.value = this.value.toString();
|
|
274
|
+
}
|
|
275
|
+
this.isProtectedOnChange = prevOnChange;
|
|
276
|
+
Input.setValue(this.value, this.respectiveElement, this.floatLabelType, this.showClearButton);
|
|
277
|
+
if (this.isHiddenInput) {
|
|
278
|
+
this.element.value = this.respectiveElement.value;
|
|
279
|
+
}
|
|
280
|
+
this.inputPreviousValue = this.respectiveElement.value;
|
|
281
|
+
/* istanbul ignore next */
|
|
282
|
+
if ((this.isAngular || this.isVue) && this.preventChange === true) {
|
|
283
|
+
this.previousValue = this.isAngular ? this.value : this.previousValue;
|
|
284
|
+
this.preventChange = false;
|
|
285
|
+
} else if (isNullOrUndefined(this.isAngular) || !this.isAngular
|
|
286
|
+
|| (this.isAngular && !this.preventChange) || (this.isAngular && isNullOrUndefined(this.preventChange))) {
|
|
287
|
+
this.raiseChangeEvent();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
case 'htmlAttributes': {
|
|
292
|
+
this.updateHTMLAttributesToElement();
|
|
293
|
+
this.updateHTMLAttributesToWrapper();
|
|
294
|
+
this.checkAttributes(true);
|
|
295
|
+
if (this.multiline && !isNullOrUndefined(this.textarea))
|
|
296
|
+
{
|
|
297
|
+
Input.validateInputType(this.textboxWrapper.container, this.textarea);
|
|
298
|
+
}
|
|
299
|
+
else
|
|
300
|
+
{
|
|
301
|
+
Input.validateInputType(this.textboxWrapper.container, this.element);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
break;
|
|
305
|
+
case 'readonly':
|
|
306
|
+
Input.setReadonly(this.readonly, this.respectiveElement);
|
|
307
|
+
break;
|
|
308
|
+
case 'type':
|
|
309
|
+
if (this.respectiveElement.tagName !== 'TEXTAREA') {
|
|
310
|
+
this.respectiveElement.setAttribute('type', this.type);
|
|
311
|
+
Input.validateInputType(this.textboxWrapper.container, this.element);
|
|
312
|
+
this.raiseChangeEvent();
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
case 'showClearButton':
|
|
316
|
+
Input.setClearButton(this.showClearButton, this.respectiveElement, this.textboxWrapper);
|
|
317
|
+
this.bindClearEvent();
|
|
318
|
+
break;
|
|
319
|
+
case 'enableRtl':
|
|
320
|
+
Input.setEnableRtl(this.enableRtl, [this.textboxWrapper.container]);
|
|
321
|
+
break;
|
|
322
|
+
case 'placeholder':
|
|
323
|
+
Input.setPlaceholder(this.placeholder, this.respectiveElement);
|
|
324
|
+
Input.calculateWidth(this.respectiveElement, this.textboxWrapper.container);
|
|
325
|
+
break;
|
|
326
|
+
case 'autocomplete':
|
|
327
|
+
if ( this.autocomplete !== 'on' && this.autocomplete !== '') {
|
|
328
|
+
this.respectiveElement.autocomplete = this.autocomplete;
|
|
329
|
+
} else {
|
|
330
|
+
this.removeAttributes(['autocomplete']);
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
333
|
+
case 'cssClass':
|
|
334
|
+
Input.updateCssClass(newProp.cssClass, oldProp.cssClass, this.textboxWrapper.container);
|
|
335
|
+
break;
|
|
336
|
+
case 'locale':
|
|
337
|
+
this.globalize = new Internationalization(this.locale);
|
|
338
|
+
this.l10n.setLocale(this.locale);
|
|
339
|
+
this.setProperties({ placeholder: this.l10n.getConstant('placeholder') }, true);
|
|
340
|
+
Input.setPlaceholder(this.placeholder, this.respectiveElement);
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Gets the component name
|
|
348
|
+
*
|
|
349
|
+
* @returns {string} Returns the component name.
|
|
350
|
+
* @private
|
|
351
|
+
*/
|
|
352
|
+
public getModuleName(): string {
|
|
353
|
+
return 'textbox';
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
protected preRender(): void {
|
|
357
|
+
this.cloneElement = <HTMLInputElement>this.element.cloneNode(true);
|
|
358
|
+
this.formElement = closest(this.element, 'form') as HTMLFormElement;
|
|
359
|
+
if (!isNullOrUndefined(this.formElement)) {
|
|
360
|
+
this.isForm = true;
|
|
361
|
+
}
|
|
362
|
+
/* istanbul ignore next */
|
|
363
|
+
if (this.element.tagName === 'EJS-TEXTBOX') {
|
|
364
|
+
const ejInstance: Object = getValue('ej2_instances', this.element);
|
|
365
|
+
const inputElement: string | HTMLInputElement | HTMLTextAreaElement = this.multiline ?
|
|
366
|
+
<HTMLTextAreaElement>this.createElement('textarea') :
|
|
367
|
+
<HTMLInputElement>this.createElement('input');
|
|
368
|
+
let index: number = 0;
|
|
369
|
+
for (index; index < this.element.attributes.length; index++) {
|
|
370
|
+
const attributeName: string = this.element.attributes[index as number].nodeName;
|
|
371
|
+
if (attributeName !== 'id' && attributeName !== 'class') {
|
|
372
|
+
inputElement.setAttribute(attributeName, this.element.attributes[index as number].nodeValue);
|
|
373
|
+
inputElement.innerHTML = this.element.innerHTML;
|
|
374
|
+
if (attributeName === 'name') {
|
|
375
|
+
this.element.removeAttribute('name');
|
|
376
|
+
}
|
|
377
|
+
} else if (attributeName === 'class') {
|
|
378
|
+
inputElement.setAttribute(attributeName, this.element.className.split(' ').filter((item: string) => item.indexOf('ng-') !== 0).join(' '));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
this.element.appendChild(inputElement);
|
|
382
|
+
this.element = inputElement;
|
|
383
|
+
setValue('ej2_instances', ejInstance, this.element);
|
|
384
|
+
}
|
|
385
|
+
this.updateHTMLAttributesToElement();
|
|
386
|
+
this.checkAttributes(false);
|
|
387
|
+
if (( isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['value'] === undefined)) && this.element.value !== '') {
|
|
388
|
+
this.setProperties({value: this.element.value}, true);
|
|
389
|
+
}
|
|
390
|
+
if (this.element.tagName !== 'TEXTAREA') {
|
|
391
|
+
this.element.setAttribute('type', this.type);
|
|
392
|
+
}
|
|
393
|
+
if (this.type === 'text' || (this.element.tagName === 'INPUT' && this.multiline && this.isReact) ){
|
|
394
|
+
this.element.setAttribute('role', 'textbox');
|
|
395
|
+
}
|
|
396
|
+
this.globalize = new Internationalization(this.locale);
|
|
397
|
+
const localeText: { placeholder: string } = { placeholder: this.placeholder };
|
|
398
|
+
this.l10n = new L10n('textbox', localeText, this.locale);
|
|
399
|
+
if (this.l10n.getConstant('placeholder') !== '') {
|
|
400
|
+
this.setProperties({ placeholder: this.placeholder || this.l10n.getConstant('placeholder') }, true);
|
|
401
|
+
}
|
|
402
|
+
if (!this.element.hasAttribute('id')) {
|
|
403
|
+
this.element.setAttribute('id', getUniqueID('textbox'));
|
|
404
|
+
}
|
|
405
|
+
if (!this.element.hasAttribute('name')) {
|
|
406
|
+
this.element.setAttribute('name', this.element.getAttribute('id'));
|
|
407
|
+
}
|
|
408
|
+
if (this.element.tagName === 'INPUT' && this.multiline) {
|
|
409
|
+
this.isHiddenInput = true;
|
|
410
|
+
this.textarea = <HTMLTextAreaElement>this.createElement('textarea');
|
|
411
|
+
this.element.parentNode.insertBefore(this.textarea, this.element);
|
|
412
|
+
this.element.setAttribute('type', 'hidden');
|
|
413
|
+
this.textarea.setAttribute('name', this.element.getAttribute('name'));
|
|
414
|
+
this.element.removeAttribute('name');
|
|
415
|
+
this.textarea.setAttribute('role', this.element.getAttribute('role'));
|
|
416
|
+
this.element.removeAttribute('role');
|
|
417
|
+
this.textarea.setAttribute('id', getUniqueID('textarea'));
|
|
418
|
+
const apiAttributes : string[] = ['placeholder', 'disabled', 'value', 'readonly', 'type', 'autocomplete'];
|
|
419
|
+
for (let index: number = 0; index < this.element.attributes.length; index++) {
|
|
420
|
+
const attributeName: string = this.element.attributes[index as number].nodeName;
|
|
421
|
+
if (this.element.hasAttribute(attributeName) && containerAttributes.indexOf(attributeName) < 0 &&
|
|
422
|
+
!(attributeName === 'id' || attributeName === 'type' || attributeName === 'e-mappinguid')) {
|
|
423
|
+
// e-mappinguid attribute is handled for Grid component.
|
|
424
|
+
this.textarea.setAttribute(attributeName, this.element.attributes[index as number].nodeValue);
|
|
425
|
+
if (apiAttributes.indexOf(attributeName) < 0) {
|
|
426
|
+
this.element.removeAttribute(attributeName);
|
|
427
|
+
index--;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private checkAttributes(isDynamic: boolean): void {
|
|
435
|
+
const attrs: string[] = isDynamic ? isNullOrUndefined(this.htmlAttributes) ? [] : Object.keys(this.htmlAttributes) :
|
|
436
|
+
['placeholder', 'disabled', 'value', 'readonly', 'type', 'autocomplete'];
|
|
437
|
+
for (const key of attrs) {
|
|
438
|
+
if (!isNullOrUndefined(this.element.getAttribute(key))) {
|
|
439
|
+
switch (key) {
|
|
440
|
+
case 'disabled':
|
|
441
|
+
if (( isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['enabled'] === undefined)) || isDynamic) {
|
|
442
|
+
const enabled: boolean = this.element.getAttribute(key) === 'disabled' || this.element.getAttribute(key) === '' ||
|
|
443
|
+
this.element.getAttribute(key) === 'true' ? false : true;
|
|
444
|
+
this.setProperties({enabled: enabled}, !isDynamic);
|
|
445
|
+
}
|
|
446
|
+
break;
|
|
447
|
+
case 'readonly':
|
|
448
|
+
if (( isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['readonly'] === undefined)) || isDynamic) {
|
|
449
|
+
const readonly: boolean = this.element.getAttribute(key) === 'readonly' || this.element.getAttribute(key) === ''
|
|
450
|
+
|| this.element.getAttribute(key) === 'true' ? true : false;
|
|
451
|
+
this.setProperties({readonly: readonly}, !isDynamic);
|
|
452
|
+
}
|
|
453
|
+
break;
|
|
454
|
+
case 'placeholder':
|
|
455
|
+
if (( isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['placeholder'] === undefined)) || isDynamic) {
|
|
456
|
+
this.setProperties({placeholder: this.element.placeholder}, !isDynamic);
|
|
457
|
+
}
|
|
458
|
+
break;
|
|
459
|
+
case 'autocomplete':
|
|
460
|
+
if (( isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['autocomplete'] === undefined)) || isDynamic) {
|
|
461
|
+
const autoCompleteTxt: string = this.element.autocomplete === 'off' ? 'off' : 'on';
|
|
462
|
+
this.setProperties({ autocomplete: autoCompleteTxt }, !isDynamic);
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
case 'value':
|
|
466
|
+
if ((( isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['value'] === undefined)) || isDynamic) && this.element.value !== '') {
|
|
467
|
+
this.setProperties({value: this.element.value}, !isDynamic);
|
|
468
|
+
}
|
|
469
|
+
break;
|
|
470
|
+
case 'type':
|
|
471
|
+
if (( isNullOrUndefined(this.textboxOptions) || (this.textboxOptions['type'] === undefined)) || isDynamic) {
|
|
472
|
+
this.setProperties({type: this.element.type}, !isDynamic);
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* To Initialize the control rendering
|
|
482
|
+
*
|
|
483
|
+
* @returns {void}
|
|
484
|
+
* @private
|
|
485
|
+
*/
|
|
486
|
+
public render(): void {
|
|
487
|
+
let updatedCssClassValue: string = this.cssClass;
|
|
488
|
+
if (!isNullOrUndefined(this.cssClass) && this.cssClass !== '') {
|
|
489
|
+
updatedCssClassValue = Input.getInputValidClassList(this.cssClass);
|
|
490
|
+
}
|
|
491
|
+
this.respectiveElement = (this.isHiddenInput) ? this.textarea : this.element;
|
|
492
|
+
this.textboxWrapper = Input.createInput({
|
|
493
|
+
element: this.respectiveElement,
|
|
494
|
+
floatLabelType: this.floatLabelType,
|
|
495
|
+
properties: {
|
|
496
|
+
enabled: this.enabled,
|
|
497
|
+
enableRtl: this.enableRtl,
|
|
498
|
+
cssClass: updatedCssClassValue,
|
|
499
|
+
readonly: this.readonly,
|
|
500
|
+
placeholder: this.placeholder,
|
|
501
|
+
showClearButton: this.showClearButton
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
this.updateHTMLAttributesToWrapper();
|
|
505
|
+
if (this.isHiddenInput) {
|
|
506
|
+
this.respectiveElement.parentNode.insertBefore(this.element, this.respectiveElement);
|
|
507
|
+
}
|
|
508
|
+
this.wireEvents();
|
|
509
|
+
if (!isNullOrUndefined(this.value)) {
|
|
510
|
+
Input.setValue(this.value, this.respectiveElement, this.floatLabelType, this.showClearButton);
|
|
511
|
+
if (this.isHiddenInput) {
|
|
512
|
+
this.element.value = this.respectiveElement.value;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (!isNullOrUndefined(this.value)) {
|
|
516
|
+
this.initialValue = this.value;
|
|
517
|
+
this.setInitialValue();
|
|
518
|
+
}
|
|
519
|
+
if (this.autocomplete !== 'on' && this.autocomplete !== '') {
|
|
520
|
+
this.respectiveElement.autocomplete = this.autocomplete;
|
|
521
|
+
} else if (!isNullOrUndefined(this.textboxOptions) && (this.textboxOptions['autocomplete'] !== undefined)) {
|
|
522
|
+
this.removeAttributes(['autocomplete']);
|
|
523
|
+
}
|
|
524
|
+
this.previousValue = this.value;
|
|
525
|
+
this.inputPreviousValue = this.value;
|
|
526
|
+
this.respectiveElement.defaultValue = this.respectiveElement.value;
|
|
527
|
+
Input.setWidth(this.width, this.textboxWrapper.container);
|
|
528
|
+
if (!isNullOrUndefined(closest(this.element, 'fieldset') as HTMLFieldSetElement) && (closest(this.element, 'fieldset') as HTMLFieldSetElement).disabled) {
|
|
529
|
+
this.enabled = false;
|
|
530
|
+
}
|
|
531
|
+
if (!this.element.hasAttribute('aria-labelledby') && !this.element.hasAttribute('placeholder') && !this.element.hasAttribute('aria-label')) {
|
|
532
|
+
this.element.setAttribute('aria-label', 'textbox');
|
|
533
|
+
}
|
|
534
|
+
this.renderComplete();
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
private updateHTMLAttributesToWrapper(): void {
|
|
538
|
+
Input.updateHTMLAttributesToWrapper(this.htmlAttributes, this.textboxWrapper.container);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
private updateHTMLAttributesToElement(): void {
|
|
542
|
+
Input.updateHTMLAttributesToElement(this.htmlAttributes, this.respectiveElement ? this.respectiveElement :
|
|
543
|
+
(this.multiline && !isNullOrUndefined(this.textarea) ? this.textarea : this.element));
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
private setInitialValue() : void {
|
|
547
|
+
if (!this.isAngular) {
|
|
548
|
+
this.respectiveElement.setAttribute('value', this.initialValue);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
private wireEvents(): void {
|
|
553
|
+
EventHandler.add(this.respectiveElement, 'focus', this.focusHandler, this);
|
|
554
|
+
EventHandler.add(this.respectiveElement, 'blur', this.focusOutHandler, this);
|
|
555
|
+
EventHandler.add(this.respectiveElement, 'keydown', this.keydownHandler, this);
|
|
556
|
+
EventHandler.add(this.respectiveElement, 'input', this.inputHandler, this);
|
|
557
|
+
EventHandler.add(this.respectiveElement, 'change', this.changeHandler, this);
|
|
558
|
+
if (this.isForm) {
|
|
559
|
+
EventHandler.add(this.formElement, 'reset', this.resetForm, this);
|
|
560
|
+
}
|
|
561
|
+
this.bindClearEvent();
|
|
562
|
+
if (!isNullOrUndefined(this.textboxWrapper.container.querySelector('.e-float-text')) && this.floatLabelType === 'Auto'
|
|
563
|
+
&& this.textboxWrapper.container.classList.contains('e-autofill') &&
|
|
564
|
+
this.textboxWrapper.container.classList.contains('e-outline')) {
|
|
565
|
+
EventHandler.add((this.textboxWrapper.container.querySelector('.e-float-text')), 'animationstart', this.animationHandler, this);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
private animationHandler() : void {
|
|
570
|
+
this.textboxWrapper.container.classList.add('e-valid-input');
|
|
571
|
+
const label: HTMLElement = this.textboxWrapper.container.querySelector('.e-float-text');
|
|
572
|
+
if (!isNullOrUndefined(label)) {
|
|
573
|
+
label.classList.add('e-label-top');
|
|
574
|
+
if (label.classList.contains('e-label-bottom')) {
|
|
575
|
+
label.classList.remove('e-label-bottom');
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
private resetValue(value: string) : void {
|
|
581
|
+
const prevOnChange: boolean = this.isProtectedOnChange;
|
|
582
|
+
this.isProtectedOnChange = true;
|
|
583
|
+
this.value = value;
|
|
584
|
+
if (value == null && this.textboxWrapper.container.classList.contains('e-valid-input') && !(this.floatLabelType === 'Always' && this.textboxWrapper.container.classList.contains('e-outline'))) {
|
|
585
|
+
this.textboxWrapper.container.classList.remove('e-valid-input');
|
|
586
|
+
}
|
|
587
|
+
this.isProtectedOnChange = prevOnChange;
|
|
588
|
+
}
|
|
589
|
+
private resetForm() : void {
|
|
590
|
+
if (this.isAngular) {
|
|
591
|
+
this.resetValue('');
|
|
592
|
+
} else {
|
|
593
|
+
this.resetValue(this.initialValue);
|
|
594
|
+
}
|
|
595
|
+
if (!isNullOrUndefined(this.textboxWrapper)) {
|
|
596
|
+
const label: HTMLElement = this.textboxWrapper.container.querySelector('.e-float-text');
|
|
597
|
+
if (!isNullOrUndefined(label) && this.floatLabelType !== 'Always') {
|
|
598
|
+
if ((isNullOrUndefined(this.initialValue) || this.initialValue === '')) {
|
|
599
|
+
label.classList.add('e-label-bottom');
|
|
600
|
+
label.classList.remove('e-label-top');
|
|
601
|
+
} else if (this.initialValue !== '') {
|
|
602
|
+
label.classList.add('e-label-top');
|
|
603
|
+
label.classList.remove('e-label-bottom');
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
private focusHandler(args: MouseEvent | TouchEvent | KeyboardEvent): void {
|
|
610
|
+
const eventArgs: FocusInEventArgs = {
|
|
611
|
+
container: this.textboxWrapper.container,
|
|
612
|
+
event: args,
|
|
613
|
+
value: this.value
|
|
614
|
+
};
|
|
615
|
+
this.trigger('focus', eventArgs);
|
|
616
|
+
}
|
|
617
|
+
private focusOutHandler(args: MouseEvent | TouchEvent | KeyboardEvent): void {
|
|
618
|
+
if (!(this.previousValue === null && this.value === null && this.respectiveElement.value === '') &&
|
|
619
|
+
(this.previousValue !== this.value)) {
|
|
620
|
+
this.raiseChangeEvent(args, true);
|
|
621
|
+
}
|
|
622
|
+
const eventArgs: FocusOutEventArgs = {
|
|
623
|
+
container: this.textboxWrapper.container,
|
|
624
|
+
event: args,
|
|
625
|
+
value: this.value
|
|
626
|
+
};
|
|
627
|
+
this.trigger('blur', eventArgs);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
private keydownHandler (args: KeyboardEvent): void {
|
|
631
|
+
if ((args.keyCode === 13 || args.keyCode === 9) && !((this.previousValue === null || this.previousValue === '') && (this.value === null || this.value === '') && this.respectiveElement.value === '')) {
|
|
632
|
+
this.setProperties({ value: this.respectiveElement.value }, true);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
private inputHandler(args: KeyboardEvent): void {
|
|
637
|
+
const textboxObj: any = null || this;
|
|
638
|
+
const eventArgs: InputEventArgs = {
|
|
639
|
+
event: args,
|
|
640
|
+
value: this.respectiveElement.value,
|
|
641
|
+
previousValue: this.inputPreviousValue,
|
|
642
|
+
container: this.textboxWrapper.container
|
|
643
|
+
};
|
|
644
|
+
this.inputPreviousValue = this.respectiveElement.value;
|
|
645
|
+
/* istanbul ignore next */
|
|
646
|
+
if (this.isAngular) {
|
|
647
|
+
textboxObj.localChange({ value: this.respectiveElement.value });
|
|
648
|
+
this.preventChange = true;
|
|
649
|
+
}
|
|
650
|
+
if (this.isVue) {
|
|
651
|
+
this.preventChange = true;
|
|
652
|
+
}
|
|
653
|
+
this.trigger('input', eventArgs);
|
|
654
|
+
args.stopPropagation();
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
private changeHandler(args: Event): void {
|
|
658
|
+
this.setProperties({value: this.respectiveElement.value}, true);
|
|
659
|
+
if (this.previousValue !== this.value)
|
|
660
|
+
{
|
|
661
|
+
this.raiseChangeEvent(args, true);
|
|
662
|
+
}
|
|
663
|
+
args.stopPropagation();
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
private raiseChangeEvent(event?: Event, interaction?: boolean): void {
|
|
667
|
+
const eventArgs: ChangedEventArgs = {
|
|
668
|
+
event: event,
|
|
669
|
+
value: this.value,
|
|
670
|
+
previousValue: this.previousValue,
|
|
671
|
+
container: this.textboxWrapper.container,
|
|
672
|
+
isInteraction: interaction ? interaction : false,
|
|
673
|
+
isInteracted: interaction ? interaction : false
|
|
674
|
+
};
|
|
675
|
+
this.preventChange = false;
|
|
676
|
+
this.trigger('change', eventArgs);
|
|
677
|
+
this.previousValue = this.value;
|
|
678
|
+
//EJ2CORE-738:For this task we update the textarea value to the input when input tag with multiline is present
|
|
679
|
+
if (this.element.tagName === 'INPUT' && this.multiline && Browser.info.name === 'mozilla') {
|
|
680
|
+
this.element.value = this.respectiveElement.value;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
private bindClearEvent(): void {
|
|
685
|
+
if (this.showClearButton) {
|
|
686
|
+
if (this.enabled) {
|
|
687
|
+
EventHandler.add(this.textboxWrapper.clearButton, 'mousedown touchstart', this.resetInputHandler, this);
|
|
688
|
+
} else {
|
|
689
|
+
EventHandler.remove(this.textboxWrapper.clearButton, 'mousedown touchstart', this.resetInputHandler);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
private resetInputHandler(event?: MouseEvent): void {
|
|
695
|
+
event.preventDefault();
|
|
696
|
+
if (!(this.textboxWrapper.clearButton.classList.contains(HIDE_CLEAR)) || this.textboxWrapper.container.classList.contains('e-static-clear')) {
|
|
697
|
+
Input.setValue('', this.respectiveElement, this.floatLabelType, this.showClearButton);
|
|
698
|
+
if (this.isHiddenInput) {
|
|
699
|
+
this.element.value = this.respectiveElement.value;
|
|
700
|
+
}
|
|
701
|
+
this.setProperties({value: this.respectiveElement.value}, true);
|
|
702
|
+
const eventArgs: InputEventArgs = {
|
|
703
|
+
event: event,
|
|
704
|
+
value: this.respectiveElement.value,
|
|
705
|
+
previousValue: this.inputPreviousValue,
|
|
706
|
+
container: this.textboxWrapper.container
|
|
707
|
+
};
|
|
708
|
+
this.trigger('input', eventArgs);
|
|
709
|
+
this.inputPreviousValue = this.respectiveElement.value;
|
|
710
|
+
this.raiseChangeEvent(event, true);
|
|
711
|
+
if (closest(this.element, 'form')) {
|
|
712
|
+
const element: Element = this.element;
|
|
713
|
+
const keyupEvent: KeyboardEvent = document.createEvent('KeyboardEvent');
|
|
714
|
+
keyupEvent.initEvent('keyup', false, true);
|
|
715
|
+
element.dispatchEvent(keyupEvent);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
private unWireEvents(): void {
|
|
721
|
+
EventHandler.remove(this.respectiveElement, 'focus', this.focusHandler);
|
|
722
|
+
EventHandler.remove(this.respectiveElement, 'blur', this.focusOutHandler);
|
|
723
|
+
EventHandler.remove(this.respectiveElement, 'keydown', this.keydownHandler);
|
|
724
|
+
EventHandler.remove(this.respectiveElement, 'input', this.inputHandler);
|
|
725
|
+
EventHandler.remove(this.respectiveElement, 'change', this.changeHandler);
|
|
726
|
+
if (this.isForm) {
|
|
727
|
+
EventHandler.remove(this.formElement, 'reset', this.resetForm);
|
|
728
|
+
}
|
|
729
|
+
if (!isNullOrUndefined(this.textboxWrapper.container.querySelector('.e-float-text')) && this.floatLabelType === 'Auto'
|
|
730
|
+
&& this.textboxWrapper.container.classList.contains('e-outline') &&
|
|
731
|
+
this.textboxWrapper.container.classList.contains('e-autofill')) {
|
|
732
|
+
EventHandler.remove((this.textboxWrapper.container.querySelector('.e-float-text')), 'animationstart', this.animationHandler);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Removes the component from the DOM and detaches all its related event handlers.
|
|
738
|
+
* Also, it maintains the initial TextBox element from the DOM.
|
|
739
|
+
*
|
|
740
|
+
* @method destroy
|
|
741
|
+
* @returns {void}
|
|
742
|
+
*/
|
|
743
|
+
|
|
744
|
+
public destroy(): void {
|
|
745
|
+
this.unWireEvents();
|
|
746
|
+
if (this.showClearButton) {
|
|
747
|
+
this.clearButton = document.getElementsByClassName('e-clear-icon')[0] as HTMLElement;
|
|
748
|
+
}
|
|
749
|
+
if (this.element.tagName === 'INPUT' && this.multiline) {
|
|
750
|
+
detach(this.textboxWrapper.container.getElementsByTagName('textarea')[0]);
|
|
751
|
+
this.respectiveElement = this.element;
|
|
752
|
+
this.element.removeAttribute('type');
|
|
753
|
+
}
|
|
754
|
+
this.respectiveElement.value = this.respectiveElement.defaultValue;
|
|
755
|
+
this.respectiveElement.classList.remove('e-input');
|
|
756
|
+
this.removeAttributes(['aria-disabled', 'aria-readonly', 'aria-labelledby']);
|
|
757
|
+
if (!isNullOrUndefined(this.textboxWrapper)) {
|
|
758
|
+
this.textboxWrapper.container.insertAdjacentElement('afterend', this.respectiveElement);
|
|
759
|
+
detach(this.textboxWrapper.container);
|
|
760
|
+
}
|
|
761
|
+
this.textboxWrapper = null;
|
|
762
|
+
Input.destroy({
|
|
763
|
+
element: this.respectiveElement,
|
|
764
|
+
floatLabelType: this.floatLabelType,
|
|
765
|
+
properties: this.properties
|
|
766
|
+
}, this.clearButton);
|
|
767
|
+
super.destroy();
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Adding the icons to the TextBox component.
|
|
772
|
+
*
|
|
773
|
+
* @param { string } position - Specify the icon placement on the TextBox. Possible values are append and prepend.
|
|
774
|
+
* @param { string | string[] } icons - Icon classes which are need to add to the span element which is going to created.
|
|
775
|
+
* Span element acts as icon or button element for TextBox.
|
|
776
|
+
* @returns {void}
|
|
777
|
+
*/
|
|
778
|
+
public addIcon(position: string, icons: string | string[]): void {
|
|
779
|
+
Input.addIcon(position, icons, this.textboxWrapper.container, this.respectiveElement, this.createElement);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Gets the properties to be maintained in the persisted state.
|
|
784
|
+
*
|
|
785
|
+
* @returns {string} Returns the persisted data.
|
|
786
|
+
*/
|
|
787
|
+
public getPersistData(): string {
|
|
788
|
+
const keyEntity: string[] = ['value'];
|
|
789
|
+
return this.addOnPersist(keyEntity);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Adding the multiple attributes as key-value pair to the TextBox element.
|
|
794
|
+
*
|
|
795
|
+
* @param {string} attributes - Specifies the attributes to be add to TextBox element.
|
|
796
|
+
* @returns {void}
|
|
797
|
+
*/
|
|
798
|
+
public addAttributes(attributes: { [key: string]: string }): void {
|
|
799
|
+
for (const key of Object.keys(attributes)) {
|
|
800
|
+
if (key === 'disabled') {
|
|
801
|
+
this.setProperties({ enabled: false }, true);
|
|
802
|
+
Input.setEnabled(this.enabled, this.respectiveElement, this.floatLabelType, this.textboxWrapper.container);
|
|
803
|
+
} else if (key === 'readonly') {
|
|
804
|
+
this.setProperties({ readonly: true }, true);
|
|
805
|
+
Input.setReadonly(this.readonly, this.respectiveElement);
|
|
806
|
+
} else if (key === 'class') {
|
|
807
|
+
this.respectiveElement.classList.add(attributes[`${key}`]);
|
|
808
|
+
} else if (key === 'placeholder') {
|
|
809
|
+
this.setProperties({ placeholder: attributes[`${key}`] }, true);
|
|
810
|
+
Input.setPlaceholder(this.placeholder, this.respectiveElement);
|
|
811
|
+
} else if (key === 'rows' && this.respectiveElement.tagName === 'TEXTAREA') {
|
|
812
|
+
this.respectiveElement.setAttribute(key, attributes[`${key}`]);
|
|
813
|
+
} else {
|
|
814
|
+
this.respectiveElement.setAttribute(key, attributes[`${key}`]);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Removing the multiple attributes as key-value pair to the TextBox element.
|
|
820
|
+
*
|
|
821
|
+
* @param { string[] } attributes - Specifies the attributes name to be removed from TextBox element.
|
|
822
|
+
* @returns {void}
|
|
823
|
+
*/
|
|
824
|
+
public removeAttributes(attributes: string[]): void {
|
|
825
|
+
for (const key of attributes) {
|
|
826
|
+
if (key === 'disabled') {
|
|
827
|
+
this.setProperties({ enabled: true }, true);
|
|
828
|
+
Input.setEnabled(this.enabled, this.respectiveElement, this.floatLabelType, this.textboxWrapper.container);
|
|
829
|
+
} else if (key === 'readonly') {
|
|
830
|
+
this.setProperties({ readonly: false }, true);
|
|
831
|
+
Input.setReadonly(this.readonly, this.respectiveElement);
|
|
832
|
+
} else if (key === 'placeholder') {
|
|
833
|
+
this.setProperties({ placeholder: null }, true);
|
|
834
|
+
Input.setPlaceholder(this.placeholder, this.respectiveElement);
|
|
835
|
+
} else {
|
|
836
|
+
this.respectiveElement.removeAttribute(key);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Sets the focus to widget for interaction.
|
|
843
|
+
*
|
|
844
|
+
* @returns {void}
|
|
845
|
+
*/
|
|
846
|
+
public focusIn(): void {
|
|
847
|
+
if (document.activeElement !== this.respectiveElement && this.enabled) {
|
|
848
|
+
this.respectiveElement.focus();
|
|
849
|
+
if (this.textboxWrapper.container.classList.contains('e-input-group')
|
|
850
|
+
|| this.textboxWrapper.container.classList.contains('e-outline')
|
|
851
|
+
|| this.textboxWrapper.container.classList.contains('e-filled')) {
|
|
852
|
+
addClass([this.textboxWrapper.container], [TEXTBOX_FOCUS]);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Remove the focus from widget, if the widget is in focus state.
|
|
859
|
+
*
|
|
860
|
+
* @returns {void}
|
|
861
|
+
*/
|
|
862
|
+
public focusOut(): void {
|
|
863
|
+
if (document.activeElement === this.respectiveElement && this.enabled) {
|
|
864
|
+
this.respectiveElement.blur();
|
|
865
|
+
if (this.textboxWrapper.container.classList.contains('e-input-group')
|
|
866
|
+
|| this.textboxWrapper.container.classList.contains('e-outline')
|
|
867
|
+
|| this.textboxWrapper.container.classList.contains('e-filled')) {
|
|
868
|
+
removeClass([this.textboxWrapper.container], [TEXTBOX_FOCUS]);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|