I grew tired to always setting the size attribute (or width via CSS) of text inputs, and I wanted my own HTML helper extension to take care of it.
My thought was, I’ll grab the max length, the same way CHtml::activeInputField obtains it, and pick from 3 or 4 preset input widths that work for the design of my page - like large/medium/small classes for text inputs, so my forms look consistent, but an input expecting less data can display as a shorter control.
For now I’ll just duplicate that code, but it would be handy if you would break that off to a separate public function? CHtml::getMaxLength() or something.
Which got me thinking. Is there potentially other "metadata" that one could obtain from validators, that could be useful for other aspects of rendering user interfaces? Perhaps a more generic API could be added that would let you obtain any property from any validator, like, say CHtml::getAttribute($model,$attribute,$validator,$property)
Although I guess this may be out of place, because it’s bordering on source code annotations, which (if implemented) should be made more generally available - an API specific to just models and validators would perhaps be too specific…
By the way, I have spent a lot of time and I am still actively working on an implementation of C#-style attributes (source code annotations) for Yii. There are at least a couple of libraries for PHP by now that implement source code annotations, and Symfony 2 will use them extensively - but every library I have seen uses a PHP-DOC style syntax, which I find misleading. Source code annotations are not documentation, they are code. And the syntax they invented for this is awful. The library I’m working on will be very fast, and the syntax will resemble PHP syntax as closely as possible. I’ve complete the parser, and an earlier prototype completed the annotation rules with support for inheritance, multiplicity and applicability rules.
Anyway, more about that soon…