@@ -4,12 +4,18 @@ import { ITextInputParams } from "./mask_utils";
4
4
export class InputElementAdapter {
5
5
private prevUnmaskedValue : string = undefined ;
6
6
7
+ private setInputValue ( value : string ) {
8
+ if ( this . inputElement . maxLength >= 0 && this . inputElement . maxLength < value . length ) {
9
+ value = value . slice ( 0 , this . inputElement . maxLength ) ;
10
+ }
11
+ this . inputElement . value = value ;
12
+ }
7
13
constructor ( private inputMaskInstance : InputMaskBase , private inputElement : HTMLInputElement , value ?: any ) {
8
14
let _value : any = value ;
9
15
if ( _value === null || _value === undefined ) {
10
16
_value = "" ;
11
17
}
12
- this . inputElement . value = inputMaskInstance . getMaskedValue ( _value ) ;
18
+ this . setInputValue ( inputMaskInstance . getMaskedValue ( _value ) ) ;
13
19
this . prevUnmaskedValue = _value ;
14
20
15
21
inputMaskInstance . onPropertyChanged . add ( this . inputMaskInstancePropertyChangedHandler ) ;
@@ -19,7 +25,7 @@ export class InputElementAdapter {
19
25
inputMaskInstancePropertyChangedHandler = ( sender : any , options : any ) => {
20
26
if ( options . name !== "saveMaskedValue" ) {
21
27
const maskedValue = this . inputMaskInstance . getMaskedValue ( this . prevUnmaskedValue ) ;
22
- this . inputElement . value = maskedValue ;
28
+ this . setInputValue ( maskedValue ) ;
23
29
}
24
30
}
25
31
@@ -32,7 +38,7 @@ export class InputElementAdapter {
32
38
beforeInputHandler = ( event : any ) => {
33
39
const args = this . createArgs ( event ) ;
34
40
const result = this . inputMaskInstance . processInput ( args ) ;
35
- this . inputElement . value = result . value ;
41
+ this . setInputValue ( result . value ) ;
36
42
this . inputElement . setSelectionRange ( result . caretPosition , result . caretPosition ) ;
37
43
if ( ! result . cancelPreventDefault ) {
38
44
event . preventDefault ( ) ;
@@ -41,7 +47,7 @@ export class InputElementAdapter {
41
47
42
48
changeHandler = ( event : any ) => {
43
49
const result = this . inputMaskInstance . processInput ( { prevValue : "" , insertedChars : event . target . value , selectionStart : 0 , selectionEnd : 0 } ) ;
44
- this . inputElement . value = result . value ;
50
+ this . setInputValue ( result . value ) ;
45
51
}
46
52
47
53
public createArgs ( event : any ) : ITextInputParams {
0 commit comments