@@ -3,6 +3,7 @@ import { DNode, PropertyChangeRecord } from '@dojo/framework/core/interfaces';
3
3
import { ThemedMixin , ThemedProperties , theme } from '@dojo/framework/core/mixins/Themed' ;
4
4
import { v , w } from '@dojo/framework/core/vdom' ;
5
5
import Focus from '@dojo/framework/core/meta/Focus' ;
6
+ import InputValidity from '@dojo/framework/core/meta/InputValidity' ;
6
7
import { FocusMixin , FocusProperties } from '@dojo/framework/core/mixins/Focus' ;
7
8
import Label from '../label/index' ;
8
9
import {
@@ -17,7 +18,6 @@ import * as css from '../theme/text-input.m.css';
17
18
import { customElement } from '@dojo/framework/core/decorators/customElement' ;
18
19
import diffProperty from '@dojo/framework/core/decorators/diffProperty' ;
19
20
import { reference } from '@dojo/framework/core/diff' ;
20
- import InputValidity from '../common/InputValidity' ;
21
21
import HelperText from '../helper-text/index' ;
22
22
23
23
export type TextInputType =
@@ -31,9 +31,7 @@ export type TextInputType =
31
31
| 'date' ;
32
32
33
33
interface TextInputInternalState {
34
- previousValue ?: string ;
35
- previousValid ?: boolean ;
36
- previousMessage ?: string ;
34
+ dirty ?: boolean ;
37
35
}
38
36
39
37
/**
@@ -155,6 +153,7 @@ export class TextInput extends ThemedMixin(FocusMixin(WidgetBase))<TextInputProp
155
153
}
156
154
private _onChange ( event : Event ) {
157
155
event . stopPropagation ( ) ;
156
+ this . _state . dirty = true ;
158
157
this . properties . onChange &&
159
158
this . properties . onChange ( ( event . target as HTMLInputElement ) . value ) ;
160
159
}
@@ -215,35 +214,23 @@ export class TextInput extends ThemedMixin(FocusMixin(WidgetBase))<TextInputProp
215
214
}
216
215
217
216
private _validate ( ) {
218
- const {
219
- _state : state ,
220
- properties : { onValidate, value, customValidator }
221
- } = this ;
222
-
223
- if ( ! onValidate || value === undefined || value === null || state . previousValue === value ) {
217
+ const { customValidator, onValidate, value = '' } = this . properties ;
218
+ const { dirty = false } = this . _state ;
219
+ if ( value === '' && ! dirty ) {
220
+ onValidate && onValidate ( undefined , '' ) ;
224
221
return ;
225
222
}
226
223
227
- state . previousValue = value ;
228
-
224
+ this . _state . dirty = true ;
229
225
let { valid, message = '' } = this . meta ( InputValidity ) . get ( 'input' , value ) ;
230
-
231
226
if ( valid && customValidator ) {
232
227
const customValid = customValidator ( value ) ;
233
228
if ( customValid ) {
234
229
valid = customValid . valid ;
235
230
message = customValid . message || '' ;
236
231
}
237
232
}
238
-
239
- if ( valid === state . previousValid && message === state . previousMessage ) {
240
- return ;
241
- }
242
-
243
- state . previousValid = valid ;
244
- state . previousMessage = message ;
245
-
246
- onValidate ( valid , message ) ;
233
+ onValidate && onValidate ( valid , message ) ;
247
234
}
248
235
249
236
protected get validity ( ) {
@@ -305,6 +292,7 @@ export class TextInput extends ThemedMixin(FocusMixin(WidgetBase))<TextInputProp
305
292
306
293
this . _validate ( ) ;
307
294
const { valid, message } = this . validity ;
295
+
308
296
const focus = this . meta ( Focus ) . get ( 'root' ) ;
309
297
310
298
const computedHelperText = ( valid === false && message ) || helperText ;
0 commit comments