Practice WOD: DigitsFormValidation

Prior to doing this WOD, you should have reviewed all the material in the Resources section of this module and watched the screencasts.

Next, create a new branch off of a successfully completed branch from the first WOD. Name this new branch “Attempt-N-1″, where N is the original branch you’re going to base this WOD on. For example, if the branch “Attempt-2″ contains the code base that you want to build this WOD on, then create a branch called “Attempt-2-1″ to indicate that this is the first attempt (1) to extend the code from “Attempt-2″ to support form processing.

Instructions

Provide validation for your Digits form. Specifically: the first name, last name, and telephone number fields should not be empty. In addition, the telephone field should be 12 characters long. Follow the three steps described in the screencast.

  1. Start your timer.
  2. Implement the validate() method in views.formdata.ContactFormData. Check to make sure all three fields are non-empty and telephone is 12 characters.
  3. Implement validation in the view. For each control, add the has-error CSS class if errors were found. Add a help-block that will display any validation errors associated with the field.
  4. Check for validation problems in the controller. Convert your controller method for the POST request into an if-then-else depending upon whether errors were found, and return badRequest rather than OK.
  5. When finished, test your code by clicking the Add button with the various kinds of validation problems.
  6. To end the WOD, commit the working code to your branch.

When finished, stop your timer, and record how many minutes it took you to complete the WOD.

Rx: <18 min Av: 18-35 min Sd: 25-30 min DNF: 30+ min

Demonstration

Once you’ve finished doing the WOD a single time, watch me do it:

Standard WOD Caveats

You’ll learn significantly less from watching me solve the WOD if you haven’t attempted the WOD yourself first.

While it’s an achievement to finish the WOD no matter how long it takes, you might experience “diminishing returns” if you work longer than the DNF time. Thus, it might be strategic to stop working at the DNF time and watch my solution.

After watching my solution, I recommend that you repeat the WOD if you have not achieved at least Av performance. If so, be sure to:

Feel free to keep trying until you make Rx if that’s of interest to you.

How to repeat the WOD

To repeat the WOD, simply switch your local workspace branch to master, then create a new branch off of master called “Attempt-2″ (or whatever attempt you are on). Then, in the play console, type ; clean ; compile ; run to clean the target directory, then recompile the system, then run the web application.