May 13, 2008

Email Validation - A Better Way

I've discovered a better way of validating email than using regular expressions.  There is now a special feature in Dojo specifically for emails.

Remove the "regexp" attribute from the HTML for the email element and replace with the following:

       regExpGen="dojox.regexp.emailAddress"

For this to work, you'll also need to add the following code to the top of the page.

      dojo.require("dojox.validate.regexp");   

This is using the dojox module which I've tried to avoid in the book but hopefully this feature will work its way into the dojo module soon!

Validating Email - Addressing the problems!

The original source code provided a regular expression for email addresses that only worked if the address was entirely upper case.  The following replacement should work better.  I've also updated the source code to reflect the new value for the regular expression.

        <input type="text" id="email" name="email" size="30"       
           dojoType="dijit.form.ValidationTextBox"
           required="true" 
           regExp="\b[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b"
           promptMessage="Enter email address."
           invalidMessage="Invalid Email Address."
           trim="true"
       />

April 13, 2008

Source Code Change for Editor Widget

An observant reader noticed that when the form is submitted after the changes in Chapter 5, the value for the text in the dijit.Editor widget is not being submitted to the server. 

The problem is that an additional field must be included in the <div> for the widget and it is that field which will then be submitted to the server.  Following is the corrected code for the widget (the source code download has also been updated).

    <div class="formRow">
      <label for="comments">Comments:</label>

      <div style ="border: 1px solid #9B9B9B; background: #FFFFFF;">
      <textarea name="comments" id="comments"
          dojoType="dijit.Editor"
          xplugins="['bold','italic','|','insertUnorderedList']"   
          >   
      </textarea>
      </div>
      <input type="hidden" name="comments2" id="comments2"
      />
    </div>

You should also download the new "Shared/submit.jsp" file (included in the new source code zip) so that you can see the data once the form is submitted.

March 03, 2008

Get the Source Code

The text of the book is available under Safari Rough Cuts which includes the first section consisting of a tutorial for using Dojo to modify a simple HTML data entry form.  You may want to download the source code rather than typing it in from the book. 

Click on the link below to download the source code as a zip file.

    Source Code For Section 1 (Chapters 1 - 5).

Note:  The source code in the book refers to Dojo version 1.2 which actually isn't available yet, although it should be by the time the printed version of the book is available.  The source code linked to above points to the current version of Dojo available now.  So it will actually work!

February 28, 2008

Here's Johnnnnny - just introducing myself

Welcome.  I'm kicking off this blog with a quick introduction and an announcement.  First the intro: I'm Jim Harmon and I teach courses for developers.  Typical classes in my repertoire cover Java in its various incarnations (the language, JEE, Open Source Frameworks, etc).  And now the announcement: I just wrote a book!  And boy are my arms tired.  The book is on Dojo, a JavaScript library, which may at first seem like it is outside my core expertise but it turns out that many of my enterprise Java clients are really getting into sprucing up their front ends with Ajax and Dojo is the perfect tool for them.

The book is called "Dojo: Using the Dojo JavaScript Library to Build AJAX Applications."  You can get more information at the book home page by clicking on the following link:

     http://safari.informit.com/9780321563132

I'll be blogging about the book, conversing with readers and listing corrections (hopefully, more of the former than the later).

This is my first book and I'm looking forward to the experience of interacting with readers.

Thanks

41gcutlvxul_ss500_