Wednesday, March 7, 2012

Using CMaskField in your yii framework

In order to supply the format of your textfield sometimes you should have to implement the specific format of your textfield. It can be solved by using the existing widget in yii framework.

You can look at this http://www.yiiframework.com/doc/api/1.1/CMaskedTextField to make CMaskedTextField that give you the alternative way to give preformatted textfield.


Oke let's take look the code :


<?php
$this->widget('CMaskedTextField', array(
'model' => $model,
'attribute' => 'aluguel',
'mask' => '(999) 999-9999? x99999',
'htmlOptions' => array('size' => 6)
));
?>
This is with the regex types
<?php
$this->widget('CMaskedTextField', array(
'model' => $model,
'attribute' => 'aluguel',
'mask' => '9.999,99',
'charMap' => array('.'=>'[\.]' , ','=>'[,]'),
'htmlOptions' => array('size' => 6)));
?>
And the final code you can see below the result here is:


.The following mask definitions are predefined:
  • a - Represents an alpha character (A-Z,a-z)
  • 9 - Represents a numeric character (0-9)
  • * - Represents an alphanumeric character (A-Z,a-z,0-9)


No comments:

Post a Comment