Search code examples
phpjqueryyiijquery-mask

Is there a CMaskedTextField option that enables to not only separate user input with characters, but also in separate textboxes?


enter image description here Im using CMaskedTextField to obtain this kind of result enter image description here However, I am actually trying to get this one

I was wondering if there was an option with CMaskedTextField that enables this feature, or in case there isnt, if anybody knows what is the most practical way in which it can be implemented. I know i could use javascript, but before i get into that im trying to squeeze Yii's provided functionalities as much as possible. Many many thks!


Solution

  • Found it. You need to specify the $placeholder property.

    Example: In your view the widget should look like this

    <?php $this->widget('CMaskedTextField', array(
                    'mask'=>'99-9999-99',
                    'name'=>'mask_tester',
                    'placeholder'=>' ',
            )); ?>
    

    Notice the placeholder is a space rather than default which is an underscore. Also, if you're passing a $model into the form you need to strike the $name property and add $model and $attribute properties.

    However, this widget will never give you separate input boxes. It will always be in one input box.