Yii Framework Forum: Cjuidatepicker - Set Current Date On Picker Binded With Model? - Yii Framework Forum

Jump to content

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

Cjuidatepicker - Set Current Date On Picker Binded With Model? Set CJuiDatePicker value when attached attribute is null Rate Topic: -----

#1 User is offline   trileletri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 12-January 12

Posted 11 September 2012 - 11:50 AM

$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $deadline,
'attribute' => 'end_time',
'flat' => true,
));


My form loads normally, and CJuidatepicker shows current date.
But when I make a mistake in form and validation occurs, after showing error summary my CJuiddatepicker shows last possible date!

I understand it is because my model attribute $deadline->end_time is not set - because of the errors, and it is
1970-01-01 00:00:00.

How to make it 'remember' which date user has selected, even if he entered other information incorrectly?

Maybe date validators? Can I make it return an error if selected day is in past? I only need future dates to be entered...
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 967
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 11 September 2012 - 12:05 PM

you can assign the end_date value from your post to the model attribute before you do the validation check
0

#3 User is offline   trileletri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 12-January 12

Posted 11 September 2012 - 11:09 PM

I will try that, it is a multi model saving function, I will look into it.

While we're at it, there are parts of form which are loaded when user clicks button (ajax), and new model instances are added into an array of models. When there is an error on form and page gets refreshed (just like datepicker) all model data that is entered into ajax loaded parts of form disappears.

Is this something like this:

$model1 = new car();
$model2 = new tyre();
$donations[] = new carparts(); //to this array I add by calling and ajax from client side
...

$valid = model1->validate();
$valid = $valid && model2->validate();


if($valid){
model1->save()
model2->save()
...
//also parts loaded via ajax into a array of models
foreach($donations as $donation)
{
    if($donation->validate())
      $donation->save();
}
}

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