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 » support » General discussion » i18n form question
i18n form question [message #68688] Sun, 28 December 2008 16:33 Go to next message
Mindphreaker  is currently offline Mindphreaker
Messages: 151
Registered: December 2008
Location: Austria
Senior Member
Hello!

I'm trying to put some I18n elements into my form. I tried the sfWidgetFormI18nDate element:

$this->widgetSchema['birthday'] = new sfWidgetFormI18nDate(array(
   'culture'   => 'en',
));


The date format should switch automatically when the user culture gets switched. Am I supposed to add more cultures in the widget options?

Another little question:
The date widget only shows me 2003 to 2013. Is this also an option or where can I configure this?

Regards,
Alex


See my favourite websites!

Complexity is relative. Relativity is complex. - Anonymous
Anyone who can give you orders can stop you from solving whatever problem you're being fascinated by. - Eric. S. Raymond
Re: i18n form question [message #68703 is a reply to message #68688 ] Sun, 28 December 2008 19:51 Go to previous messageGo to next message
Mindphreaker  is currently offline Mindphreaker
Messages: 151
Registered: December 2008
Location: Austria
Senior Member
At least I found a solution to pass the user culture to the form:

$this->form = new myForm(null, array('culture' => $this->getUser()->getCulture()));

public function getCurrentCulture()
{
   return isset($this->options['culture']) ? $this->options['culture'] : 'en';
}


The second thing is still unsolved, does someone know how to configure the date range shown up in the year field? For a birthday field it should show up at least 100 years backwards from the current year.


See my favourite websites!

Complexity is relative. Relativity is complex. - Anonymous
Anyone who can give you orders can stop you from solving whatever problem you're being fascinated by. - Eric. S. Raymond
Re: i18n form question [message #69347 is a reply to message #68688 ] Wed, 07 January 2009 10:49 Go to previous messageGo to next message
Sn0wm4n  is currently offline Sn0wm4n
Messages: 5
Registered: January 2009
Location: Germany
Junior Member
Hi Mindphreaker,

I had the same problem, too (using symfony 1.2.1)
In the official symfony API there isn't a solution yet (or I don't see it).

But 'sfWidgetFormI18nDate' has a option 'years' in order to define a range of years shown in the form.

Here a snippet I use for my form (also for date of birth):

$currentYear = date("Y");
// save all possible years (for the ages 18 to 100)
$birthdayYears = range($currentYear-118, $currentYear-18);

// set the widget
'birthday' => new sfWidgetFormI18nDate( array('culture' => 'en', 'years' => $birthdayYears) ),


kind regards,
Sn0wm4n
Re: i18n form question [message #69349 is a reply to message #69347 ] Wed, 07 January 2009 11:10 Go to previous messageGo to next message
Mindphreaker  is currently offline Mindphreaker
Messages: 151
Registered: December 2008
Location: Austria
Senior Member
Thanks a lot!

I was searching around in the documentations but could not find such a parameter.

Maybe this code snippet should be implemented in the documentation.


See my favourite websites!

Complexity is relative. Relativity is complex. - Anonymous
Anyone who can give you orders can stop you from solving whatever problem you're being fascinated by. - Eric. S. Raymond
Re: i18n form question [message #69632 is a reply to message #68703 ] Sun, 11 January 2009 05:34 Go to previous message
inde  is currently offline inde
Messages: 14
Registered: December 2008
Junior Member
Mindphreaker wrote on Sun, 28 December 2008 19:51

At least I found a solution to pass the user culture to the form:

$this->form = new myForm(null, array('culture' => $this->getUser()->getCulture()));

public function getCurrentCulture()
{
   return isset($this->options['culture']) ? $this->options['culture'] : 'en';
}




This can also be done using the sfContext:

$this->widgetSchema['birthday'] = new sfWidgetFormI18nDate(array(
   'culture'   => sfContext::getInstance()->getUser()->getCulture(),
));


[Updated on: Sun, 11 January 2009 05:35]

Previous Topic:propel 1.3 configuration without using DSN
Next Topic:Building Own Generator
Goto Forum:
  

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