The Problem
Over time we have developed a number of bespoke data capture solutions, such as application forms for complex financial products (e.g. mortgages and pensions). These, like most sophisticated applications, rapidly go beyond the simple validation capabilities of existing frameworks, and a number of issues begin to surface.
These cover a variety of cross cutting concerns, such as:
- Cross-field validation - the rules that are applied to one field are often related to the values stored in one or more other fields.
- Scoping rules - various questions / sections of the form may be optional depending on the answers made elsewhere in the form.
- Deployment - a simple rule change often results in the need to perform a full deployment.
- Testing - even with the best of intentions, it is common for some of the validation code to get mixed in with the UI code, making automated testing far more difficult and brittle.
- Maintenance - as the inter-relationships between fields and rules grows more complex, there is a tendency for the code to degrade. The likelihood of introducing some subtle bug (for example, failing to check a rule when a particular field changes) grows ever more likely and progress slows to a crawl.
And, of course, the Solution
As a result of experiencing this pain a number of times ourselves, we knew there had to be a better way. Our approach was to abstract these issues away from the core UI code and into a self-contained engine. The result - Rich Internet Forms, a developer framework that tackles the problem head-on.
Below is a little more detail on the implementation and the impact it has on your project. But before that, here it is. This demo is a simple mockup of a page from a UK tax return where all the validation that you see is being handled by RIF. Note that all the UI element highlighting that is performed is handled via XAML, and hence is completely under your control - RIF doesn't impose any form of UI styling. Also note the Issues section at the bottom which dynamiclly updates as you modify fields. You can even click on the errors in the Issues box and RIF will automatically put the focus on the appropriate UI element.
If this sounds interesting, then give us a call to discuss your needs.
The Details
RIF is a sophisticated rules engine that is driven by an external rules file. This straightaway solves the deployement issue - the vast majority of rule changes are now restricted to a single text file which can be deployed in isolation.
From the rules definition, RIF hooks into your View Model and builds an internal dependency tree. As UI events are raised, it automatically works out which rules are affected and hence can restrict evaluation to just those necessary. When rules fire, RIF then displays the appropriate errors. Again, this is fully automatic.
The result is that validation concerns are completely removed from the UI code. Lifted from this burden, the code can now stay clean and maintainable, and changes to requirements can be handled very quickly. The rules themselves, now that they are freed from the UI, can also be tested using your favourite unit testing framework.
Interestingly, the adoption of RIF has given us new options in how forms are presented to the user, which was an unexpected side effect. One of the ways we tried to keep validation logic under control in a pre-RIF world was to enforce a fairly linear approach (think Wizard and you've got the idea). With the validation burden removed, RIF has enabled us to easily create complex forms where the user can interact in a very non-linear manner. Getting this level of flexbility in user experience design for "free" is very useful.
RIF currently targets WPF and Silverlight (v2 upwards). As with anything of this nature, it does have its own learning curve and so rather than having a simple download link we prefer a small consultative period where we can share with you our experiences and best practices. How long is needed would obviously depend on yuor requirements, but we'd expect it to be 5 days or less.
Finally, for those looking for a HTML/Javascript solution, there is no practical reason why RIF could not be ported to run in that environment. The only reason we haven't yet is simply that we've not yet had the need. Please give us a call is this is something you'd require.