DRY or not?

One of the web applications requirements is to provide a rich user experience. Client side validation and formatting is a part of this UX. The subject I want to address today is how to achieve a good level of UX on formatting with respect to one of the OO principles, DRY principle.

The case is simple, user can edit multiple date inputs, that are reformatted right away. The screen would look like this:

Item #1 delivery date:
Sunday, 15/02/2008
Item #2 delivery date:
Monday, 16/02/2008
...  

Where's the DRY issue is raising - formatting can be done on server side and on the client side. One of the requirements is to reformat the value right as it is entered. One of the options is to use Ajax - well, a suicidal option. Another one, to invoke some client side code (client presentation logic?) to do the formatting. But as soon as this is done, the logic is replicated on server and client. Or is it?

The solution I go with is to have the logic centralized in a single location, execution of the logic done in different places. Having formatting rule in one location would allow to 'downsize' the replication of things. Formatting string identical to the one that .NET has will be passed to the client side code (JavaScript). That same code will leverage something like regular expression (or anything else that will assist reformatting).

So how dry is that? Probably not the best solution, so what are your ways to solve this?

No Comments