CMaskedTextField

Hi,

How can I use CMaskedTextField to format a Date/Time database field (MySQL) to "hh:mm"?

Tks

BSC

Use ??:?? as the mask.

Can you please show me an example of the full code line…

Tks




<?php

$this->widget('CMaskedTextField', array(

		'model' => $model,

		'value' => $model->isNewRecord ? $model->your_attribute_name : '',

		'attribute' => 'your_attribute_name',

		'mask' => '99:99:99',

		'htmlOptions' => array('size' => 10)

		)

 	);

?>



I bit off-topic and just guessing, as I never used CMaskedTextEdit.

But since it should be similar to other model-related, active form elements, then you don’t have to provide value, the way you use value parameter in your example. It should work fine, with model and attribute parameters set, in both situations (editing existing one or creating new model).

If I’m not mistaken, for widgets like this (and many more - for example CGridView/CDetailView columns) you provide either value or model+attribute, not both at the same time.

I did follow the instructions but not effective!

I want set max hour <= 24 and minute <= 59.

Definelo en las reglas con el siguiente codigo





array('Hora', 'match', 'pattern'=>'/^(0[0-9]|1\d|2[0-3])<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />[0-5]\d)$/', 'message' => 'Tu mensaje de error'),






<?php

$this->widget('CMaskedTextField', array(

                'model' => $model,

                'value' => $model->isNewRecord ? $model->your_attribute_name : '',

                'attribute' => 'your_attribute_name',

                'mask' => '23:59:59',

                'htmlOptions' => array('size' => 10)

                )

        );

?>



I think this is what he was looking for… Which would allow up to 23:59:59, but I don’t see how you’d be able to do 24 without going to 24:59:59 on the inputs (without writing javascript)