Has anyone extended CHtml for HTML5 elements?

I’m working on a site that would benefit from using HTML5 input fields (email validation, phone numbers etc) and was wondering if anyone’s had the opportunitiy to code an extension to CHTML class to include HTML5 elements.

I noticed there’s been a ticket about this for nearly 2 years:

http://code.google.com/p/yii/issues/detail?id=580

Has anyone had opportunity to develop this and be willing to share? Or are there any plans in 1.1.9 to add these new input types to the CHTML class?

Thanks!

Nope. Haven’t thought of it yet. But this would be a good start. You should take into strong consideration that those HTML5 elements won’t work in most browsers being used (still tons of users use IE, and not Chrome or FF users have updated their browsers).

My solution for old browsers that don’t support them is to use a shim to plug the functionality in where it’s not currently supported.

Specifically, part of the webshims library:

http://afarkas.github.com/webshim/demos/index.html

I have a quick fix that allows me to use CHTML to draw custom fields. I’ve modified “/framework/web/helpers/chtml.php”, and modified line 1106 (from Yii 1.1.8) and modified the following code from:


protected static function inputField($type,$name,$value,$htmlOptions)

… to …


public static function inputField($type,$name,$value,$htmlOptions)

This allows you to call this function directly, like so:


echo CHtml::inputField('search', get_class($mdl)."[". $str_Field ."]", $mdl->$str_Field, array('maxlength'=>100));

This means I get a proper HTML5 search field where available. It’s not perfect, but it’s a start.