Keith Devens .com |
Friday, May 16, 2008 | ![]() |
| "What is truth?" – Pontius Pilate | ||
|
| ← Neat freeware | LiveJournal → |

Keith Gaughan (http://hereticmessiah.weblogs.com/) wrote:
Keith (http://www.keithdevens.com/) wrote:
I noticed you were working on that
. I've written things like that in the past, where I could automatically generate forms from information in a database, for example. But to make it work for the general case it seemed like you have to go through so much effort parameterizing everything that it becomes not worth it, and you still can't get it as flexible as you need.
Needless to say, I'm very interested to see what you come up with.
About the selected="selected" thing. You're right. I've been writing my HTML like I did above for years. They were boolean attributes, so I assumed the values must be "true" and "false". I just assumed that when I started, and never actually checked the spec to make sure -- "true" and "false" as values for boolean attributes was so obvious!
It seems silly that the value of the 'selected' attribute is "selected" while the value of the 'checked' attribute is "checked", even though they're both boolean attributes (same goes for multiple="multiple"). It also seems silly that you don't have symmetry, so you can have 'selected="selected"' but not 'selected="unselected"', which the more obvious 'selected="true"' and 'selected="false"' gives you.
But... the joke's on me
. Thanks a bunch for pointing that out. I probably would have continued doing it that way for years if you hadn't stopped me.
Keith Gaughan (http://hereticmessiah.weblogs.com/) wrote:
Dumb, I know, but I guess it was backwards compatibility the W3C were thinking about at the time.
Here's the basic scheme for the IAT (in PHP anyhow): the library consists of a set of classes that represent elements of the form.
There's the IATForm class, which forms the core of the toolkit. This dispatches messages to other classes to build the HTML JavaScript to represent the form and the validation code, and does the server-side validation too.
Each type of form element is represented by its own class, with some subtle differences like how textareas and textfields are handled by the same class, a textfield being used if the height is one and a text area otherwise.
Then there's the validation classes. These range from checking to see if the text entered is a date or if it fits a given regexp to checking that the correct range of checkboxes have been checked. This sort of thing is the primary reason for writing it - I hate writing validation code with a passion.
The last set of classes are more or less project bound - they're formatting stratagies for laying out the form. This is the sort of thing I've been writing a lot of at work so that I could reuse the various classes I'd written in VBScript and VB in different projects. It also means I can change the whole look and feel of an application in ways I wouldn't be able to do with CSS on it's own and would be too difficult to do with raw HTML.
For an example of a set of classes that are written along similar lines, take a look at QryListing, a set of VBScript classes to handle rendering listings of queries. There's a reasonable amount of code there, and it would be fair to say that it in some ways it seems bit overengineered, but as soon as the code was written, it infested the rest of the company's applications. And to thin I wrote it for my bug tracker!
IAT fits into the same kind of patterns as the QryListing suite. In fact, because PHP supports inheritance, it'll be much nicer to implement and extend than it's predessessor was. I'm also going to convert QryListing over. I've been meaning to for a while but never had a chance.
Keith Gaughan (http://hereticmessiah.weblogs.com/) wrote:
The thing is, has anybody ever actually written anything like this before. It'd be cool if they hadn't. The closest thing I can think of is WebForms in ASP.NET, but that seems to take a different stratagy and I was already thinking about IAT before I knew about WebForms.
ColdFusion has special tags which also produce client-side validation code, but they're a bit crap and I don't know anybody who ever uses those tags.
Know of anything?
Keith (http://www.keithdevens.com/) wrote:
I don't know enough about WebForms - I should learn. It's amazing how big .Net even long before anything's really released. It's like the technology isn't real yet, but everyone talks about it as if it were.
The only thing I know that does similar things to what you're doing -- making it easier to write form code, including both server-side and client-side validation -- is a project called SteelBlue. It's open source, but I don't think it's changed in a while. I think it was written by some PhD's. Might be worth taking a look at, but it's its own language/environment, it's not something like a class library that can fit into an existing language.
Adam Vandenberg wrote:
ASP.Net is a (kinda-sorta) welcome change for people who've been doing form hand coding in ASP all this time. The (sadly defunct) Encarta Experts project would have taken a bit less time with ASP.Net vs ASP, because ASP.Net has an easier to use framework for dealing with web forms.
Doing a form declaratively vs. response.writing out HTML is great, and being able to specify predicates for element validation is keen too.
ASP.Net as a whole, I don't know, I haven't had enough exposure to it. Some things are nice and simple, some things still feel big and clunky.
(The Conversatron, my side-coproject site in Python, is chock full of the Python version of the PHP snippet above.)
Keith Gaughan (http://hereticmessiah.weblogs.com/) wrote:
SteelBlue: smells terribly like some elements of CF to me.
ASP.NET's not all that bad. It'd definitely a huge improvement over Classic ASP, AFAIC. It's gained a lot of the nice things about Java through .NET, and the fact that each page is a class pretty much rocks. It's actually bearable now.
WebForms is one of the best and least well-known parts of the new framework. I was rather chuffed when I saw it. It's really cool. It doesn't have formatting stratagies, but hey...
OTOH, ADO.NET is a bit clunky. Oh well...
Seeing as all the IAT code is going to be just a bunch of classes that plug into one another to allow you to create & process forms declaratively, it should be easy enough to convert over to Python. When I get the basic class framework done, I'll post it up on my site.
I'm really surprised nobody's ever done this before...
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.327s.
(Used 8 db queries)
Uh-hu! That's why I'm planning to write those Interface Abstraction Toolkits for PHP and CF. Form building, automatic client- and server-side validation, enforcing a standard look and feel, blah, blah, blah, it'll do it.
I'm going to make the code freely available for anybody who wants to use it when it's reached a decent state.
BTW, shouldn't that be selected="selected"?