Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Learning Dart Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Spiral 2 – how to validate data with Dart


If you have tested the Spiral 1 – the power of HTML5 forms version thoroughly, you would have come across some things that could be improved:

  1. The HTML5 control only does its checks when the Create Account button is clicked; it would be better if the user is alerted earlier, preferably after filling in each field.

  2. The Birth Date value is checked to be a correct DateTime value, but a value in the future is accepted.

  3. The Gender field will gladly accept other values than M or F.

  4. The Balance field accepts a negative number.

So, HTML5 doesn't give us full validation possibilities. To remedy and supplement this, we must add code validation, see bank_terminal_s2.dart:

Note

For the code files of this section, refer to chapter 6\bank_terminal_s2 in the code bundle.

InputElement name, address, email, birth_date, gender;
InputElement number, balance, pin_code;
void main() {
  // bind variables to DOM elements:
  name = querySelector('#name');
  address = querySelector...