Skip to content

Commit

Permalink
doc about adding possibility to filter with choice
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Suez authored and ornicar committed Jun 16, 2010
1 parent be3106e commit fe16bf1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions reference/en/09 - Admin generator.markdown
Expand Up @@ -186,3 +186,35 @@ $(function(){
});
});
[/code]

##Custom filters

### Filtering with a choice widget
Many time we define types of some field:
[code php]
class PersonTable extends myDoctrineTable
{
static public $genders = array(
1 => 'Male',
2 => 'Female',
);
}
[/code]

In the form filter, the autogenerated widget is and input, but we would like to use a choice, so we change the widget:

[code php]
public function configure()
{
//add empty choice
$gender_choices = array(null => null) + PersonTable::$genders;

$this->widgetSchema['gender'] = new sfWidgetFormChoice(array(
'choices' => $gender_choices
));
$this->validatorSchema['gender'] = new sfValidatorChoice(array(
'required' => false,
'choices' => array_keys($gender_choices)
));
}
[/code]

0 comments on commit fe16bf1

Please sign in to comment.