Eva Dias
Eva Dias

Reputation: 1747

change the range of years shown on a select box - symfony

In my field created_at, in both newSuccess.php and editSuccess.php, is a select box and it only shows years from 2006 to 2016. How can I change this to show older years?

Upvotes: 0

Views: 1327

Answers (1)

domi27
domi27

Reputation: 6923

You could set the "years" option of the sfWidgetFormDate which is part of sfWidgetFormDateTime

// e.g. this year till 1960
$years = range(round(date("Y")), 1960);

// get the DateWidget
$this->widgetSchema["created_at"]->getDateWidget()->setOption("years", $years);

If you only need the date component, I would suggest to overwrite the basic form

$this->widgetSchema["created_at"] = new sfWidgetFormDate(array("years" => $years));

See also

Upvotes: 1

Related Questions