File tree 2 files changed +25
-1
lines changed
tests/cypress/integration/plugins
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,16 @@ export default function (Alpine) {
40
40
}
41
41
42
42
// Override x-model's initial value...
43
- if ( el . _x_model ) el . _x_model . set ( el . value )
43
+ if ( el . _x_model ) {
44
+ // If the x-model value is the same, don't override it as that will trigger updates...
45
+ if ( el . _x_model . get ( ) === el . value ) return
46
+
47
+ // If the x-model value is `null` and the input value is an empty
48
+ // string, don't override it as that will trigger updates...
49
+ if ( el . _x_model . get ( ) === null && el . value === '' ) return
50
+
51
+ el . _x_model . set ( el . value )
52
+ }
44
53
} )
45
54
46
55
const controller = new AbortController ( )
Original file line number Diff line number Diff line change @@ -89,6 +89,21 @@ test('x-mask with x-model with initial value',
89
89
} ,
90
90
)
91
91
92
+ test ( 'x-mask with x-model if initial value is null it should remain null' ,
93
+ [ html `
94
+ < div x-data ="{ value: null } ">
95
+ < input x-mask ="(999) 999-9999 " x-model ="value " id ="1 ">
96
+ < input id ="2 " x-model ="value ">
97
+ < span id ="3 " x-text ="value === null ? 'NULL' : value "> </ span >
98
+ </ div >
99
+ ` ] ,
100
+ ( { get } ) => {
101
+ get ( '#1' ) . should ( haveValue ( '' ) )
102
+ get ( '#2' ) . should ( haveValue ( '' ) )
103
+ get ( '#3' ) . contains ( 'NULL' )
104
+ } ,
105
+ )
106
+
92
107
test ( 'x-mask with a falsy input' ,
93
108
[ html `< input x-data x-mask =""> ` ] ,
94
109
( { get } ) => {
You can’t perform that action at this time.
0 commit comments