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 » [SOLVED] admin-gen + dropdown list filter customization
icon11.gif  [SOLVED] admin-gen + dropdown list filter customization [message #91749] Tue, 19 January 2010 12:04 Go to next message
godbout  is currently offline godbout
Messages: 13
Registered: October 2009
Location: Macau
Junior Member
Hi!

I'm having trouble to make a custom filter using a dropdown list. I have 2 tables with a relationship and I want to use the field of one of the table in the other's one filter.

I succeeded to draw the dropdown in the filter, but I can't handle correctly the sql query.

In my form filter I've declared the dropdown like this:

$this->widgetSchema['code'] = new sfWidgetFormDoctrineChoice(array(
      'model' => 'TplProgram',
      'add_empty' => '',
      'method' => 'getCode',
    ));
		$this->validatorSchema['code'] = new sfValidatorDoctrineChoice(array(
		  'model' => 'TplProgram',
		  'required' => false,
		));


I've got 2 other methods in the form filter:

public function getFields()
	{
		return array_merge(array(
			'code' => 'Code',
			), 
			parent::getFields());
	}


and

protected function addCodeColumnQuery(Doctrine_Query $query, $field, $values)
	{
	  $alias = $query->getRootAlias();
	  $query->innerJoin($alias .'.TplProgram T')->addWhere('T.code = "?"', $values);
	}


The problem is that in the last method, I don't receive the text chosen, but the values of it (1, 2, 3).

One solution is to receive the value, but I don't know. Another one is to force FormDoctrineChoice to use the text as a value, but I don't know...

Thx in advance for the help.

[Updated on: Wed, 20 January 2010 07:10]

Re: admin-gen + dropdown list filter customization [message #91826 is a reply to message #91749 ] Wed, 20 January 2010 07:09 Go to previous messageGo to next message
godbout  is currently offline godbout
Messages: 13
Registered: October 2009
Location: Macau
Junior Member
$this->widgetSchema['code'] = new sfWidgetFormDoctrineChoice(array(
      'model' => 'TplProgram',
      'add_empty' => '',
      'method' => 'getCode',
'key_method' => 'getCode',
    ));


Works great like this.
Now I have a trouble with my Doctrine query, but that's another problem...

[Updated on: Wed, 20 January 2010 07:09]

Re: admin-gen + dropdown list filter customization [message #97829 is a reply to message #91826 ] Thu, 22 April 2010 04:28 Go to previous message
Brahm  is currently offline Brahm
Messages: 4
Registered: March 2010
Junior Member
This post saved me a bunch of time, many thanks!

It's unfortunate that there are tutorials on this subject but they are hella outdated ( http://trac.symfony-project.org/wiki/HowtoAddCustomFilterCri teria) and the tutorial does not go deep enough on the subject of filters. The only thing missing is to add some JS to link both filters so that when the first one is selected, the second one changes accordingly =)

[Updated on: Thu, 22 April 2010 04:32]

Previous Topic:Dynamic folder in sfWidgetFormInputFileEditable
Next Topic:Admin generator and Cascaded Foreign Keys
Goto Forum:
  

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