eWorld.UI - Matt Hawley

Ramblings of Matt

MVC UI Validation Framework

April 2, 2008 16:36 by matthaw

The last few days I've been working on a MVC UI validation framework that closely follows that of ASP.NET. While my implementation is only in it's baby steps, I decided I would post it to the MVC Contrib project, and follow as much standards as what they have. Overall, the framework is very simple and straight forward in it's use.

Here were my requirements:

  1. It must closely match the ASP.NET UI validation framework.
  2. It should support all of the ASP.NET validators in their minimalistic implementation.
  3. It should require very minimal script inclusion or code to make this happen.
  4. It should only by a client side framework as you should be protecting your data on the server side through normal validations.

What I came up with, includes:

  1. It utilizes the ASP.NET UI validation framework by leveraging the WebUIValidation.js file (emitted through WebResource.axd).
  2. It supports all of the validators, with extended support for validation groups:
    1. RequiredValidator
    2. RegularExpressionValidator
    3. RangeValidator (currently does not support Date or Currency data types)
    4. CompareValidator
    5. CustomValidator
  3. It exposes 2 script inclusion calls, and 1 form validation setup call
    1. ValidatorRegistrationScripts() - Will render the WebUIValidation.js script, and scripts for form validation upon submission. This should be placed within the head tag.
    2. ValidatorInitializationScripts() - Will render all of the "expando" attributes for all validators upon the page and any initialization calls to set things up. This should be placed at the very end of your page before the closing body tag.
    3. FormValidation() - Will return an IDictionary object containing the "onsubmit" attribute. This should be called when creating your <form> tag.
  4. It is only a client-side framework leveraging ASP.NET's WebUIValidation.js

Since you now have an idea of the requirements and what was met, here's an example of it in action:

   1:  <%@ Import Namespace="MvcContrib.UI.Html" %>
   2:  <html>
   3:     <head>
   4:        <%= Html.Form().ValidatorRegistrationScripts() %>
   5:     </head>
   6:     <body>
   7:        <% using(Html.Form<MyController>(c => c.Save(), FormMethod.Post, Html.Form().FormValidation())) { %>
   8:        First Name: <%= Html.TextBox("firstName") %>
   9:        <%= Html.Form().RequiredValidator("firstNameRequired", "firstName", "First Name is Required.") %>
  10:        <%= Html.Form().RegularExpressionValidator("firstNameRegex", "firstName", "[a-zA-Z]*", "First Name can only contain letters.") %>
  11:        <br />
  12:        Age: <%= Html.TextBox("age") %>
  13:        <%= Html.Form().RequiredValidator("ageRequired", "age", "Age is Required.") %>
  14:        <%= Html.Form().RegularExpressionValidator("ageRegex", "age", "[0-9]*", "Age can only be numeric.") %>
  15:        <%= Html.Form().RangeValidator("ageRange", "age", "18", "35", ValidationDataType.Integer, "Age is not in target range of 18-35.") %>
  16:        <br />
  17:        <%= Html.SubmitButton("submit", "Save") %>
  18:        <% } %>
  19:        <%= Html.Form().ValidatorInitializationScripts() %>
  20:     </body>
  21:  </html>

At this point, I've posted it as a patch to MVC Contrib project, and hoping they apply it Smile. If you would like to get your hands on it, check out the patches page, mine is #1063. Please let me know your input, I tried making it as simple as possible to use, and I believe I've achieved that.

Update: My patch has been applied by Eric :) Get the latest build (>= 0.0.1.96) it if you'd like to check this out. Also, let me know of any issues you may find by logging bugs on the CodePlex site.



Released: Excentrics World Server Controls v2.0.6

January 23, 2007 23:54 by matthaw

Version 2.0.6 of Excentrics World Server Controls has just been released targeting Microsoft AJAX Extensions, RTM (didn't know it was released, visit ScottGu's blog post announcing it!) to ensure continued full compatibility as well as a few bug fixes. It should be noted with this release, the control set's compatibility layer will no longer be compatible with any prior versions of Microsoft AJAX Extensions. A breaking change from 2.0.5 to 2.0.6 is that the compatibility layer no longer includes validation controls, following suit with Microsoft AJAX.

The items that were fixed are:

  • Fixed issue where the culture, if not set, was pulling from CurrentUICulture instead of CurrentCulture for the CalendarPopup and TimePicker.
  • Fixed issue where if the culture set for the CalendarPopup or TimePicker was a neutral culture, that it would attempt to resolve a specific culture for parsing of the date & time.
  • Fixed an issue where pasting into the NumericBox in IE with valid text that had whitespace surrounding it would fail.

The updated version can be downloaded by visiting http://www.eworldui.net/Download.aspx. The official build number for this release is 2.0.6.2393.



Windows Developer Power Tools

January 11, 2007 07:36 by matthaw

I've been keeping this under wraps for about 6 months now, but since the book has been finally published & I just received my copy, I'm happy to promote the book Windows Developer Power Tools.I was asked by James Avery and Jim Holmes to be a contributor writing about Unleash It. Check out the book as it has a ton of awesome free & open source tools, and read my section (12.8) starting on page 650. Yay!



EntLib 3.0 CTP

December 23, 2006 04:41 by matthaw

Ohh, just in time for the holidays, Enterprise Library 3.0 has just had it's first CTP released. Might have to give it a whirl to see what I can use from it versus the current 2.0 version I'm using. Some of the new features look interesting, especially the new Validation Application Block & Application Block Software Factory. Good thing I'm leaving my computer behind, otherwise I think my wife would divorce me. Check out the new site on CodePlex.



Categories: .NET | Development
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

FogBugz getting an API & VS2005 Plugin!

December 22, 2006 16:29 by matthaw

Yes, the title says it all. FogBugz is getting an exposed API (oddly enough feels like WebServices but isn't even close - rar!) in the next version. The good news is there's a beta version of this API already out that enables a new Visual Studio 2005 Plugin to see your cases by your various filters. I've been wanting something like this for home for quite awhile, so I'm quite happy to see this finally exists. I would have posted sooner about this, but it was a rocky start for the API as it's already on (my version #, not there's) 1.2 due to some bugs not allowing me or many others to work with it. So definately check this out if you're using FogBugz and Visual Studio 2005 & hate to have a separate IE window open to manage your bugs.



Microsoft AJAX & Google AdSense

December 22, 2006 16:22 by matthaw

I was bitten by this bug that was introduced in Microsoft AJAX RC. It seems that Microsoft AJAX is overriding the default implementation of Date.parse from Javascript with it's own implementation. Normally this isn't a bad idea, but it only accepted a certain set of templates when parsing making Google AdSense break upon loading on the page. Luckily enough, some developer named Cyril has a workaround available. The forum post and his blog entry (in French) have more information. Those visiting my website should no longer have a Javascript error displayed as I've implemented this workaround temporarily.



Released: Excentrics World Server Controls v2.0.5

December 18, 2006 06:15 by matthaw

Version 2.0.5 of Excentrics World Server Controls has just been released targeting Microsoft AJAX Extensions, RC1 to ensure continued full compatibility as well as some other bug fixes. It should be noted that with this release, the control set will no longer be compatible with any prior versions of Microsoft AJAX Extensions. The items that were added/fixed are:

  • Added disabling auto-complete for the calendar/timepicker textbox.
  • Fixed issue where supplying less decimal characters than the max specified would throw an exception upon postback for the Numeric Box.
  • Fixed issue where readonly was enabled on the Numeric Box and typing over selected text would delete the text.
  • Fixed enabling or disabling the Calendar Popup control via client script multiple times so that the control doesn't display the calendar when clicking on the image.
  • Fixed issue where setting Nullable=True, the visible date was 1/1/1900 on the Calendar Popup.
  • Fixed month/year popup from jumping 10 years down to 5 years since that is what is displayed on the Calendar Popup.

The updated version can be downloaded by visiting http://www.eworldui.net/Download.aspx. The official build number for this release is 2.0.5.2356.



Released: Excentrics World Server Controls v2.0.4

November 18, 2006 22:12 by matthaw

Version 2.0.4 of Excentrics World Server Controls has just been released targeting just two annoyance bugs that were introduced with v2.0.3. The control set has also been compiled against Microsoft AJAX Extensions, Beta 2 to ensure continued full compatibility - however it'll still function just fine with Beta 1. The bugs that were fixed were:

  • Fixed issue where the *Image types for the CalendarPopup and TimePicker were not being rendered correctly to the client.
  • Fixed issue where the next month link or image was being displayed outside of the calendar.

The updated version can be downloaded by visiting http://www.eworldui.net/Download.aspx. The official build number for this release is 2.0.4.2327.



Released: Excentrics World Server Controls v2.0.3

November 1, 2006 14:52 by matthaw

I'm happy to announce that Excentrics World Server Controls has hit version 2.0.3. This version focuses primarily on Microsoft AJAX Extensions, Beta 1 support enabling developers to utilize the Excentrics World Server Controls through a compatibility layer. The full change-list is as follows:

  • Full compatibility with Microsoft AJAX Extensions, Beta 1.
  • Added support for applying the ToolTip to the title hyperlink in the CollapsablePanel.
  • Added support for a valid alpha or numeric character within the MaskedTextBox using the character 'x' as the indicator.
  • Fixed issue where setting the calendar width was not applying correctly in the CalendarPopup.
  • Fixed issue where selecting the same date/time would raise client side events in the CalendarPopup and TimePicker.
  • Fixed issue where setting the Page Culture to something other than en-US would not display the calendar correctly in the CalendarPopup.
  • Fixed issue where special day styling was not being applied correctly to weekdays and weekends in the CalendarPopup.
  • Fixed issue with Internet Explorer when the control is contained within a scrollable div in the CalendarPopup and TimePicker.

For information regarding the compatibility mode with Microsoft AJAX Extensions, Beta 1, please view the Read Me document installed with the setup utility.

The updated version can be downloaded by visiting http://www.eworldui.net/Download.aspx. The official build number for this release is 2.0.3.2310.



Released: Excentrics World Server Controls v2.0.2

September 14, 2006 15:58 by matthaw

I’m proud to announce that Excentrics World Server Controls has released v2.0.2. This has been a work in progress for about a month now with the biggest issue finally resolved, full Microsoft “Atlas” compatibility support! The full change-list is as follows:

  • Full compatibility with Microsoft “Atlas” for all controls.
  • Added ability to enable/disable the CalendarPopup and TimePicker controls via Client-side Javascript API.
  • Fixed validator controls not working with non en-US cultures.
  • Fixed the display of the visible year for non-Gregorian calendars for the CalendarPopup.
  • Fixed issue where setting PopupLocation=Left on the CalendarPopup and TimePicker never actually displayed the popups on the left.
  • Fixed the issue where the CollapsablePanel was not retaining the expanded/collapsed state upon postback.
  • Fixed the NumericBox not posting back when AutoPostBack=True
  • Fixed issue where AutoFillFormat was not applying the mask when reaching a non-alpha/numeric character.
  • Fixed tabbing into the MaskedTextBox by handling it more gracefully now when typing characters.
  • Fixed issue where the multi-text drop down list and list box controls were not binding correctly against the selected value when contained in a DetailsView / FormView.

Along with the v2.0.2 release, there has been a price drop in licensing the source code. The cost is now $75 USD instead of $100 USD. Lastly, some website enhancements have been made, most notably the integration with my weblog displaying the latest 5 entries relating to website news.

The updated version can be downloaded by visiting http://www.eworldui.net/Download.aspx. The official build number for this release is 2.0.2.2264.





Copyright © 2000 - 2025 , Excentrics World