Yii Framework Forum: CMaskedTextField - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CMaskedTextField Can I use CMaskedTextField to have a hh:mm format? Rate Topic: -----

#1 User is offline   BSC 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 30-November 10
  • Location:Portugal

Posted 03 December 2010 - 08:34 AM

Hi,

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

Tks
BSC
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 04 December 2010 - 11:28 AM

Use ??:?? as the mask.
"Less noise - more signal"
0

#3 User is offline   BSC 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 30-November 10
  • Location:Portugal

Posted 04 December 2010 - 11:49 AM

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

Tks
0

#4 User is offline   cactork 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 30-October 10
  • Location:Buenos Aires, Argentina.

Posted 22 November 2011 - 06:17 AM

View PostBSC, on 04 December 2010 - 11:49 AM, said:

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)
		)
 	);
?>

0

#5 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,197
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 26 November 2011 - 10:33 AM

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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#6 User is offline   Mao Danh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 20-August 12

Posted 12 September 2012 - 08:32 AM

View Postcactork, on 22 November 2011 - 06:17 AM, said:

<?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 did follow the instructions but not effective!
I want set max hour <= 24 and minute <= 59.
0

#7 User is offline   elsr.doo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 15-May 12

Posted 06 February 2013 - 02:58 PM

View PostMao Danh, on 12 September 2012 - 08:32 AM, said:

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]):([0-5]\d)$/', 'message' => 'Tu mensaje de error'),

0

#8 User is offline   MichaelG 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-October 10
  • Location:Roseville, CA

Posted 25 March 2013 - 08:17 PM

View PostMao Danh, on 12 September 2012 - 08:32 AM, said:

I did follow the instructions but not effective!
I want set max hour <= 24 and minute <= 59.



<?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)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users