This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » Setting the default for sfWidgetFormDateTime
Setting the default for sfWidgetFormDateTime [message #89476] Mon, 07 December 2009 13:45 Go to next message
pfwd  is currently offline pfwd
Messages: 31
Registered: June 2009
Location: Wiltshire
Member
Hi,
This has already been asked by someone else in the 1.1 forum some time ago but hasn't been answered:
http://forum.symfony-project.org/index.php/m/73357/?srch=sfW idgetFormDateTime#msg_73357

How do you set the default for the sfWidgetFormDateTime widget?
In the form class I have:
		
$years = range(date('Y'), date('Y') +10);
$years_list = array_combine($years, $years);
$this->widgetSchema['start_date'] = new 

sfWidgetFormDateTime(array(
'date' =>array(
'format'=>'%day% - %month% - %year%',
'can_be_empty' =>false,
'years' =>$years_list
)
)
);


I've tried:
$this->widgetSchema['start_date']->setDefault(date('c', time()));


			
$this->widgetSchema['start_date'] = new sfWidgetFormDateTime(array(
'date' =>array(
'format'=>'%day% - %month% - %year%',
'can_be_empty' =>false,
'years' =>$years_list
),
'default'=>'2010-10-02 10:10'
)
);

and other similar things with no luck.

Any chance some one could show me how to do this.

Thanks

[Updated on: Mon, 07 December 2009 13:51]

Re: Setting the default for sfWidgetFormDateTime [message #89498 is a reply to message #89476 ] Mon, 07 December 2009 17:57 Go to previous messageGo to next message
defaka  is currently offline defaka
Messages: 43
Registered: February 2007
Member

You can do it in 2 ways

1. In your action class

public function executeNew(sfWebRequest $request)
{
  $this->yourmodel = new YourModel();
  $this->yourmodel->setStartDate(date('c', time());
  $this->yourmodelform = new YourModelForm($this->yourmodel);
}


or..

2. Override the form updateDefaultsFromObject()

public function updateDefaultsFromObject()
{
  parent::updateDefaultsFromObject();
  if ($this->getObject()->isNew())
  {
    $this->setDefault('start_date', date('c', time()));
  }
}


i hope it help!!!

[Updated on: Mon, 07 December 2009 17:59]

Re: Setting the default for sfWidgetFormDateTime [message #89516 is a reply to message #89476 ] Mon, 07 December 2009 20:15 Go to previous messageGo to next message
Levelx  is currently offline Levelx
Messages: 358
Registered: April 2009
Location: Germany
Faithful Member
I think you only used the wrong sytax!
You can set it easyly in the configure() method of your form.

$this->setDefault('start_date', time());


It's a method of the form, not the widget!
Re: Setting the default for sfWidgetFormDateTime [message #89548 is a reply to message #89516 ] Tue, 08 December 2009 13:56 Go to previous messageGo to next message
pfwd  is currently offline pfwd
Messages: 31
Registered: June 2009
Location: Wiltshire
Member
Levelx wrote on Mon, 07 December 2009 19:15

I think you only used the wrong sytax!
You can set it easyly in the configure() method of your form.

$this->setDefault('start_date', time());


It's a method of the form, not the widget!


That worked a treat
thanks
Re: Setting the default for sfWidgetFormDateTime [message #97991 is a reply to message #89548 ] Sat, 24 April 2010 15:16 Go to previous message
morferic  is currently offline morferic
Messages: 11
Registered: April 2010
Junior Member
for the Italian date format 'd-m-Y H:i' i used this (and works!):



/* Put it in the configure method of the form class */

//this for set the correct date format
$this->widgetSchema['Data_Richiesta']->setOption('date',
array(
'format'=>'%day% %month% %year%',
));

//this for set the default value
$this->setDefault('date', date('Y-m-d H:i', time()));


Thank you for this post!

Eric R.
Previous Topic:a modal popup from updater?
Next Topic:the old "Who is online" function
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software