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.1 » [SOLVED] Setting widget default options in BaseFormPropel
[SOLVED] Setting widget default options in BaseFormPropel [message #64545] Tue, 04 November 2008 18:35 Go to next message
annis  is currently offline annis
Messages: 18
Registered: September 2008
Location: Germany
Junior Member
Hey all,

in the new forms book there is little snippet I'd like to use ( http://www.symfony-project.org/book/forms/1_1/en/04-Propel-I ntegration#Generating%20Form%20Classes, a little further down on "Global Customization of Propel Forms"). It says there that all base form classes inherit from this uber-base form. An example is given on how to change the default form formatter name - this is accessed via a static method.

Now, my question is: how do I setup default options for a certain widget? Take for example the format and months options of sfWidgetFormDate. I have at least 4 forms that need this in the same format and need the months not as numbers but as 'January' etc.

I can't call the setOption method as it's not a static method, so is this even possible?

On the other hand: why have this base class at all, then?


Cheers, Daniel

[Updated on: Thu, 06 November 2008 23:17]

Re: Setting widget default options in BaseFormPropel [message #64602 is a reply to message #64545 ] Wed, 05 November 2008 23:39 Go to previous messageGo to next message
annis  is currently offline annis
Messages: 18
Registered: September 2008
Location: Germany
Junior Member
Well, that weren't that many answers.

At least the problem with the months I solved - just use sfWidgetFormI18nDate.

But I have all these useless, non-DRY lines of pure, boiler-plate configuration code in all my forms, which is pretty annoying.

Does anyone know anything about the base form configuration of all base forms?

Thanks in advance!

Cheers, Daniel
Re: Setting widget default options in BaseFormPropel [message #64694 is a reply to message #64602 ] Thu, 06 November 2008 20:40 Go to previous messageGo to next message
barros  is currently offline barros
Messages: 12
Registered: June 2008
Junior Member
Hi Daniel.

I think it's not possible to have a default options for a widget, but I think you can do one tiny trick. I didnt test it, but I guess this should work. The idea is, on the global BASE class you search through all your widgets and for those of type sfWidgetFormDate, you apply your settings.. the code would be something like this:

abstract class BaseFormPropel extends sfFormPropel
{
  public function setup()
  {
  	foreach($this->getWidgetSchema()->getFields() as $name=>$widget)
  	{
  		if($widget instanceof sfWidgetFormI18nDate)
  			$this[$name]->setOption('format','your_format_here');
  	}
  }
}


This way ALL your sfWidgetFormI18nDate widgets will have the same format option, but this will apply to the WHOLE application.

Hope this helps Smile

Carlos Barros
Re: Setting widget default options in BaseFormPropel [message #64711 is a reply to message #64545 ] Thu, 06 November 2008 23:16 Go to previous messageGo to next message
annis  is currently offline annis
Messages: 18
Registered: September 2008
Location: Germany
Junior Member
Thank you very much, I just had to change it a little bit because sfForm throws an exception when you try it like this:

$this[$name]->setOption('format','your_format_here');


Now, instead do it like this:

$this->widgetSchema[$name]->setOption('format','your_format_here');



And that's it. Thanks again! Daniel
Re: Setting widget default options in BaseFormPropel [message #64712 is a reply to message #64711 ] Thu, 06 November 2008 23:18 Go to previous message
barros  is currently offline barros
Messages: 12
Registered: June 2008
Junior Member
Oh, yes, I didn't notice this.

Thanks

Carlos
Previous Topic:build-form - plugin - propel 1.3 issue
Next Topic:Forms
Goto Forum:
  

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