Timepicker Problem

Hi! I have one question here. Is it possible to use timepicker extension more than one time at once? I tried it before and I found out that I can’t save the second data. Could anyone please help me? Please correct me if there is any mistake. Thanks in advance.

Here’s my code:




<tr>

	<td><?php echo $form->labelEx($model,'start'); ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start',                    //the data is saved successully

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start1',                     //the data is not saved

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start2',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start3',

    ));

    ?></td></br></tr>


	<tr style="background: #FFFFB2">

	<td><?php echo $form->labelEx($model,'end'); ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end1',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end2',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end3',

    ));

    ?></td></tr>



5420

Untitled.png

May be usefull check this

I too had the same issue and the link helped thanks

I got another issue. My datepicker doesn’t popup on initial click after page load. Rather when I click on the page once the datepicker pops up in the later clicks

Hi, thanks for the reply. I used to refer to the link before but it doesn’t seems working to me. I can save the first data but I’m having problem to save the rest of the data. I put the different id for the ‘name’.

Does anyone knows what’s the problem?

Here’s my code:




<tr>

	<td><?php echo $form->labelEx($model,'start'); ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start1',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start2',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start3',

    ));

    ?></td></br></tr>


	<tr style="background: #FFFFB2">

	<td><?php echo $form->labelEx($model,'end'); ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end1',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end2',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end3',

    ));

    ?></td></tr>



Try to check post data as




print_r($_POST);



data and also check does your used extension provides that feature?

Install fire bug .Run your application in firefox .

see the inspectElement view

How to create datepicker name and values passed or see in page source

Thank you so much for the reply. I did debug and try to see what’s the error but it didn’t show any error. I can’t figure out what is actually the problem is. As I mentioned earlier, I can save the first start and end time. However, I can’t save the following start and end time. Is there anything that I miss out??

my view file:




<div class="form">

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(

	'id'=>'course-form',

	'enableAjaxValidation'=>false,

        'method'=>'post',

	'type'=>'horizontal',

	'htmlOptions'=>array(

		'enctype'=>'multipart/form-data'

	)

)); ?>

	

    <fieldset style="margin-left:10px; margin-right:10px; background-color:#FFFFE0">

    <h3><p class="note">Course Details</p></h3>	

    <h5><p class="note">Fields with <span class="required">*</span> are required.</p></h5></br>


	<?php echo $form->errorSummary($model,'Opps!!!', null,array('class'=>'alert alert-error span12')); ?>

	

    <div class="control-group" style="margin-left:50px;>		

    <div class="span4">

	

	<?php echo $form->textFieldRow($model,'code',array('class'=>'span5')); ?>


	<?php echo $form->textFieldRow($model,'name',array('class'=>'span5')); ?>


	<div style="margin-left:70px">

    <?php echo $form->labelEx($model,'type'); ?>

	<div style="margin-left:110px; margin-top:-30px">

	<?php echo $form->dropDownList($model,'type', CHtml::listData(CourseType::model()->findAll(), 'type', 'type'), array('empty'=>'Please Select Course Type','style'=>'width:350px')); ?>

    </div></div></br>


	<?php echo $form->textFieldRow($model,'credit_hour',array('class'=>'span5')); ?>


	<div style="margin-left:30px">

    <?php echo $form->labelEx($model,'prerequisite'); ?>

	<div style="margin-left:150px; margin-top:-30px">

	<?php echo $form->textArea($model,'prerequisite',array('class'=>'span5','maxlength'=>1000)); ?>

    </div></div></br>

	

	<div style="margin-left:30px">

    <?php echo $form->labelEx($model,'session'); ?>

	<div style="margin-left:150px; margin-top:-30px">

	<?php 

	$yearNow = date("Y");

    $yearFrom = $yearNow - 4;

    $arrYears = array();

	

    foreach (range($yearFrom, $yearNow) as $number) {

        $arrYears[$number] = $number;		

    }

	

	echo $form->dropDownList($model,'session',$arrYears,array('style'=>'width:100px')); ?> / <?php

	echo $form->dropDownList($model,'session2',$arrYears,array('style'=>'width:100px')); ?> - <?php

	echo $form->dropDownList($model,'semester',array('Sem 1'=>'Sem 1 (Feb-May)','Sem 2'=>'Sem 2 (Sept-Jan)','Sem 3'=>'Sem 3 (Jun-July)'),array('style'=>'width:155px'));

	?>

    </div></div></br>

	

	<?php echo $form->textFieldRow($model,'total_student',array('class'=>'span5')); ?>

	</fieldset>

	

	<fieldset style="margin-left:10px; margin-right:10px; background-color:#FFFFE0">

	<h3><p class="note">Class Details</p></h3>

	<table style="margin-top:-60px;">

	

	<tr style="background: #FFFFB2">

	<td>Class Details</td>

	<td>Class 1</td>

	<td>Class 2</td>

	<td>Class 3</td>

	<td>Class 4</td>

    </br></tr>

	

	<tr>

	<td><?php echo $form->labelEx($model,'class_type'); ?></td>

	<td><?php echo $form->dropDownList($model,'class_type', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>

	<td><?php echo $form->dropDownList($model,'class_type1', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>

	<td><?php echo $form->dropDownList($model,'class_type2', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>

	<td><?php echo $form->dropDownList($model,'class_type3', array('Lecture'=>'Lecture','Tutorial'=>'Tutorial','Lab'=>'Lab'), array('empty'=>'Please Select Class')); ?></td>

    </br> </tr>

	

	<tr style="background: #FFFFB2">

	<td><?php echo $form->labelEx($model,'day'); ?></td>

	<td><?php echo $form->dropDownList($model,'day', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>

	<td><?php echo $form->dropDownList($model,'day1', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>

	<td><?php echo $form->dropDownList($model,'day2', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>

	<td><?php echo $form->dropDownList($model,'day3', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?></td>

    </br></tr>


	<tr>

	<td><?php echo $form->labelEx($model,'start'); ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start1',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start2',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'start3',

    ));

    ?></td></br></tr>


	<tr style="background: #FFFFB2">

	<td><?php echo $form->labelEx($model,'end'); ?></td>

	<td><?php

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end1',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end2',

    ));

    ?></td>

	<td><?php 

    $this->widget('ext.timepicker.timepicker', array(

    'model'=>$model,

    'name'=>'end3',

    ));

    ?></td></tr>

	

	</table>

    </div></div>   

	</table>

     

	<div class="form-actions">

		<?php $this->widget('bootstrap.widgets.TbButton', array(

			'buttonType'=>'submit',

			'type'=>'primary',

            'icon'=>'ok white',  

			'label'=>$model->isNewRecord ? 'Create' : 'Save',

		)); ?>

        <?php $this->widget('bootstrap.widgets.TbButton', array(

			'buttonType'=>'reset',

            'icon'=>'remove',  

			'label'=>'Reset',

		)); ?>

	</div>

</fieldset> 


<?php $this->endWidget(); ?>

</div>




my model file:




<?php


/**

 * This is the model class for table "course".

 *

 * The followings are the available columns in table 'course':

 * @property integer $id

 * @property string $code

 * @property string $name

 * @property string $type

 * @property integer $credit_hour

 * @property string $prerequisite

 * @property string $session

 * @property string $session2

 * @property string $semester

 * @property integer $total_student

 * @property string $class_type

 * @property string $day

 * @property string $start

 * @property string $end

 * @property string $class_type1

 * @property string $day1

 * @property string $start1

 * @property string $end1

 * @property string $class_type2

 * @property string $day2

 * @property string $start2

 * @property string $end2

 * @property string $class_type3

 * @property string $day3

 * @property string $start3

 * @property string $end3

 */

class Course extends CActiveRecord

{

	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'course';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('code, name, type, credit_hour, session, session2, semester, total_student, class_type, day, start, end', 'required'),

			array('credit_hour, total_student', 'numerical', 'integerOnly'=>true),

			array('code', 'length', 'max'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,

			array('name', 'length', 'max'=>100),

			array('type, semester', 'length', 'max'=>50),

			//array('prerequisite', 'length', 'max'=>1000),

			array('session, session2', 'length', 'max'=>4),

			array('class_type, day, class_type1, day1, class_type2, day2, class_type3, day3', 'length', 'max'=>20),

			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.

			array('id, code, name, type', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'code' => 'Course Code',

			'name' => 'Course Name',

			'type' => 'Course Type',

			'credit_hour' => 'Credit Hour',

			'prerequisite' => 'Course Prerequisite',

			'session' => 'Session/Semester',

			//'session2' => 'Session2',

			//'semester' => 'Semester',

			'total_student' => 'Total Student',

			'class_type'=> 'Class Type',

			'day' => 'Class Day',

			'start' => 'Class Start',

			'end' => 'Class End',

			// 'class_type1' => 'Class Type1',

			// 'day1' => 'Day1',

			// 'start1' => 'Start1',

			// 'end1' => 'End1',

			// 'class_type2' => 'Class Type2',

			// 'day2' => 'Day2',

			// 'start2' => 'Start2',

			// 'end2' => 'End2',

			// 'class_type3' => 'Class Type3',

			// 'day3' => 'Day3',

			// 'start3' => 'Start3',

			// 'end3' => 'End3',

		);

	}

	

	public function afterSave() {

        if($this->isNewRecord){

            $model2 = new CourseClass();

			$model2->course_id = $this->id;

			$model2->class_type = $this->class_type;

			$model2->day = $this->day;

			$model2->start = $this->start;

			$model2->end = $this->end;

			

			$model2->class_type1 = $this->class_type1;

			$model2->day1 = $this->day1;

			$model2->start1 = $this->start1;

			$model2->end1 = $this->end1;

			

			$model2->class_type2 = $this->class_type2;

			$model2->day2 = $this->day2;

			$model2->start2 = $this->start2;

			$model2->end2 = $this->end2;

			

			$model2->class_type3 = $this->class_type3;

			$model2->day3 = $this->day3;

			$model2->start3 = $this->start3;

			$model2->end3 = $this->end3;

			

            $model2->save(false);

        }

    }

	

	private $idCache; 


    public function beforeDelete()

    {

        $this->idCache = $this->id;


        return parent::beforeDelete();

    }


	

	public function afterDelete()

    {

        $criteria = new CDbCriteria(array(

        'condition' =>'id=:id',

        'params' => array(

        ':id' => $this->idCache),

        ));


        $children = CourseTimetable::model()->findAll($criteria);


        foreach ($children as $child)

        {

            $child->delete();

        }


        parent::afterDelete();

    }


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 *

	 * Typical usecase:

	 * - Initialize the model fields with values from filter form.

	 * - Execute this method to get CActiveDataProvider instance which will filter

	 * models according to data in model fields.

	 * - Pass data provider to CGridView, CListView or any similar widget.

	 *

	 * @return CActiveDataProvider the data provider that can return the models

	 * based on the search/filter conditions.

	 */

	public function search()

	{

		// @todo Please modify the following code to remove attributes that should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('code',$this->code,true);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('type',$this->type,true);

		$criteria->compare('credit_hour',$this->credit_hour);

		$criteria->compare('prerequisite',$this->prerequisite,true);

		$criteria->compare('session',$this->session,true);

		$criteria->compare('session2',$this->session2,true);

		$criteria->compare('semester',$this->semester,true);

		$criteria->compare('total_student',$this->total_student);

		$criteria->compare('class_type',$this->class_type,true);

		$criteria->compare('day',$this->day,true);

		$criteria->compare('start',$this->start,true);

		$criteria->compare('end',$this->end,true);

		$criteria->compare('class_type1',$this->class_type1,true);

		$criteria->compare('day1',$this->day1,true);

		$criteria->compare('start1',$this->start1,true);

		$criteria->compare('end1',$this->end1,true);

		$criteria->compare('class_type2',$this->class_type2,true);

		$criteria->compare('day2',$this->day2,true);

		$criteria->compare('start2',$this->start2,true);

		$criteria->compare('end2',$this->end2,true);

		$criteria->compare('class_type3',$this->class_type3,true);

		$criteria->compare('day3',$this->day3,true);

		$criteria->compare('start3',$this->start3,true);

		$criteria->compare('end3',$this->end3,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}


	/**

	 * Returns the static model of the specified AR class.

	 * Please note that you should have this exact method in all your CActiveRecord descendants!

	 * @param string $className active record class name.

	 * @return Course the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}

}




You need to add UNIQUE ids to all of your timepickers. ie.




....your code....

'htmlOptions'=>array(

'id'=>'my_id'

),

...the rest of the code....


next time picker

....your code....

'htmlOptions'=>array(

'id'=>'my_id_2'

),

...the rest of the code....



that should solve them not showing up right.

Hi, skworden. Thanks for your help. I have try to add ‘id’ into my codes but it is still not saving into the database. Is there anything I did wrongly?? Or did I missed out anything?




<td><?php echo $form->labelEx($model,'start'); ?></td>

	<td><?php 

    $this->widget('application.extensions.jui_timepicker.JTimePicker', array(

    'model'=>$model,

     'attribute'=>'start',

     // additional javascript options for the date picker plugin

     'options'=>array(

         'showPeriod'=>true,

         ),

     'htmlOptions'=>array('id'=>'start','size'=>8,'maxlength'=>8 ),

    ));

    ?></td>

	

	<td><?php 

    $this->widget('application.extensions.jui_timepicker.JTimePicker', array(

    'model'=>$model,

     'attribute'=>'start1',

     // additional javascript options for the date picker plugin

     'options'=>array(

         'showPeriod'=>true,

         ),

     'htmlOptions'=>array('id'=>'start1','size'=>8,'maxlength'=>8 ),

    ));

    ?></td>

	

	<td><?php 

    $this->widget('application.extensions.jui_timepicker.JTimePicker', array(

    'model'=>$model,

     'attribute'=>'start2',

     // additional javascript options for the date picker plugin

     'options'=>array(

         'showPeriod'=>true,

         ),

     'htmlOptions'=>array('id'=>'start2','size'=>8,'maxlength'=>8 ),

    ));

    ?></td>



Is there anyone having the same problem with me? Anyone knows how to solve this?? Thanks in advance.

According the code of the ext,




		$options=CJavaScript::encode($this->options);

		$js = "jQuery('#{$id}').timepicker($options);";



you need to have an ID of the object where you want to call it.

Suggestion

1 - check the generated code and inspect that is the timepicker is called for all the object where you want?

2 - If you are using same configurations for all of the object, then remove that part of code and add this at the end of page




$(document).ready(function() {

$('.hasTimepicker').timepicker(); 

});



Hi, PeRoChAk. Thank you so much for the reply. I know that I need to have an ID so that I can call the object. I thought that the ‘name’ is refer to the ID of each object field,is it correct?

But, where do I need to put the ID? I have even tried to add ‘id’ into the code but it is still can’t save into the database except for the first timepicker. Only the first timepicker can be saved.




......

<tr>

        <td><?php echo $form->labelEx($model,'start'); ?></td>

        <td><?php 

    $this->widget('ext.timepicker.timepicker', array(

	'id'=>'start',

    'model'=>$model,

    'name'=>'start',

    ));

    ?></td>

        <td><?php 

    $this->widget('ext.timepicker.timepicker', array(

	'id'=>'start1',

    'model'=>$model,

    'name'=>'start1',

	));

    ?></td>

        <td><?php 

    $this->widget('ext.timepicker.timepicker', array(

	'id'=>'start2',

    'model'=>$model,

    'name'=>'start2',

    ));

    ?></td>

        <td><?php 

    $this->widget('ext.timepicker.timepicker', array(

	'id'=>'start3',

    'model'=>$model,

    'name'=>'start3',

    ));

    ?></td></br></tr>

.....



What do u mean by adding this part of code of my last page? Can you explain more on this? Thank you.




$(document).ready(function() {

$('.hasTimepicker').timepicker(); 

});



I think your code looks fine for the IDs and names.

Can you add


var_dump($_POST);

in the Controller action?

Thus in the


if(isset($_POST)){ die(var_dump($_POST));}

.

Then after posting, you can see what variables are sent to the Controller.

In the $model 1 database, the dates are also not stored? Are the dateformats

correct? I’ve once had that I was trying to save a dd-mm-yyyy in a yyyy-mm-dd

sql format, then sql just skips the format and it stores ‘0000-00-00’.

Please provide us the var_dump($_POST) data.

Hi, FOX Creation. I have solved my problem. Thanks guys for helping me to solve my problem. Have a nice day :lol:

Dear Beginner123, is it possible to share the solution?

Not necessarily for me, but for others who might read this topic later.

Thanks.

Ohh, sure! I have missed out of putting my field ID in my model file. After I adding the ID, it can save into my database. Thanks.

Here’s my model file:




<?php




class Course extends CActiveRecord

{

	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'course';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('code, name, type, credit_hour, session, session2, semester, total_student, class_type, day, start, end, venue', 'required'),

			array('credit_hour, total_student', 'numerical', 'integerOnly'=>true),

			array('code', 'length', 'max'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,

			array('name', 'length', 'max'=>100),

			array('type, semester, venue, venue1, venue2, venue3', 'length', 'max'=>50),

			array('session, session2', 'length', 'max'=>4),

			array('class_type, day, start1, start2, start3, end1, end2, end3, class_type1, day1, class_type2, day2, class_type3, day3', 'length', 'max'=>20),       //here is where i add my field id of start1,start2,start3,end1,end2,end3

			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.

			array('id, code, name, type', 'safe', 'on'=>'search'),

		);

	}

.....