Permalink
Browse files

fix: Initializes empty form with fields marked as invalid

  • Loading branch information...
MikeMitterer committed Dec 15, 2016
1 parent f7daac7 commit 30dfc346eaf49697cfdfdb1bf2be5fa9a1f564b5
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/src/components/MaterialTextfield.dart
@@ -183,7 +183,6 @@ class MaterialTextfield extends MdlComponent with FallbackFormatter {
eventStreams.add(element.onKeyDown.listen( _onKeyDown ));
}
final bool isInvalid = element.classes.contains(_cssClasses.IS_INVALID);
_updateClasses();
/// Reformat according to [MaterialFormatter] definition
@@ -192,10 +191,19 @@ class MaterialTextfield extends MdlComponent with FallbackFormatter {
}
_kickInFormatter();
element.classes.add(_cssClasses.IS_UPGRADED);
if (isInvalid) {
element.classes.add(_cssClasses.IS_INVALID);
final bool isInvalid = element.classes.contains(_cssClasses.IS_INVALID);
// If field is invalid but empty we reset the invalid-class during this initialization
// phase.
//
// E.g. - solves the problem of showing an empty Login-Form empty fields marked as error.
// We turn this flag on after the user keys something in or field looses focus
// (Form becomes dirty)
if (isInvalid && value.isEmpty) {
element.classes.remove(_cssClasses.IS_INVALID);
}
element.classes.add(_cssClasses.IS_UPGRADED);
}
}
}

0 comments on commit 30dfc34

Please sign in to comment.