How to set default date in sfWidgetFormDate?

Discussion specific to symfony 1.1.x stable

Moderator: hartym

How to set default date in sfWidgetFormDate?

Postby relaximadoctor » Wed Oct 01, 2008 5:04 am

How do you set the default date (or default date time) for an sfFormWidgetDate/sfFormWidgetDatetime? I feel like the answer to this question must be obvious, but I cannot figure it out. This is in Symfony 1.1.

I have read:
The forms chapter (10) of the Symfony book
Chapters 1-4 of the separate forms book

I have also looked at:
The API of sfWidgetFormDate and it's parents
The API of sfFormField/sfFormFieldSchema

Things I have tried:
sfWidgetFormDate::setAttribute('value', date);
sfWidgetFormDate::setOption('value', date); //clearly wrong, but whatever
sfForm::setDefault('date_field', date);
I have used both timestamps, arrays, and dates for the date value.

Also, if the solution to this is in the docs, mind pointing it out and how you found it?
relaximadoctor
Junior Member
 
Posts: 2
Joined: Wed Sep 24, 2008 5:41 am

Re: How to set default date in sfWidgetFormDate?

Postby montes » Wed Oct 08, 2008 2:01 pm

same problem here, impossible to set default date (no problem with other widgets)

PS: symfony 1.1.4
montes
Junior Member
 
Posts: 3
Joined: Wed Oct 08, 2008 1:58 pm

Re: How to set default date in sfWidgetFormDate?

Postby montes » Wed Oct 08, 2008 9:44 pm

solved!!

CTRL+R is a bad idea to test forms... :oops:
montes
Junior Member
 
Posts: 3
Joined: Wed Oct 08, 2008 1:58 pm

Re: How to set default date in sfWidgetFormDate?

Postby relaximadoctor » Thu Oct 09, 2008 3:24 am

...so the solution was?
relaximadoctor
Junior Member
 
Posts: 2
Joined: Wed Sep 24, 2008 5:41 am

Re: How to set default date in sfWidgetFormDate?

Postby montes » Thu Oct 09, 2008 9:12 am

I think it was more a mistake reloading the page than other type of error.

Code: Select all
   //Year range to show in birthday field
   $years = range(1910, 1990);
    $this->campo = $this->form['birthday']->getWidget();
    $this->campo->setOption('years' , array_combine($years, $years));
   
    //We fill the form fields with actual data
    $this->form->setDefaults(array(
       'first_name' => $this->getUser()->getProfile()->getFirstName(),
       'last_name' => $this->getUser()->getProfile()->getLastName(),
       'birthday' => $this->getUser()->getProfile()->getBirthday(),
       'email' => $this->getUser()->getProfile()->getEmail(),       
    ));
montes
Junior Member
 
Posts: 3
Joined: Wed Oct 08, 2008 1:58 pm

Re: How to set default date in sfWidgetFormDate?

Postby jacksprat » Thu Oct 15, 2009 2:07 am

For a sfWidgetFormDate, you can set defaults as follows:


To set it to today's date:

$this->setDefault('start_date', date('Y/m/d'));

To set it to any date as year/month/day:

$this->setDefault('start_date', '2009/10/5');
jacksprat
Junior Member
 
Posts: 4
Joined: Fri Oct 02, 2009 3:24 pm


Return to symfony 1.1

Who is online

Users browsing this forum: No registered users and 1 guest