logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$4
Why do the years not appear in the form date widgets?

Look at the screenshot. On the left you can see the created_at value in the database. On the right you can see it on the screen. The years do not appear. I'm having this problem with every date widget, where the date is from a source that I just imported.

Symfony 1.4.

Why are the years not showing up?

This question has been answered.

attachment image asker uploaded image

Lawrence Krubner | 01/07/11 at 5:47pm Edit


The experts have suggested, on average, a prize of $4 for this question.

(2) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/26/11
    2:08pm
    Gabor Fasi says:

    The year widget's options contain a few years back and forth from the current one by default. It's just guesswork without seeing the html source, but I believe 2005 is not included in the created_at wiget's options, thus selection the default empty option.

    sfWidgetFormDate has an optional `years` option, where you can specify which years you want to have it displayed.

  • avatar
    Last edited:
    01/26/11
    2:08pm
    Loban Rahman says:

    Check out the contents of configure() for sfWidgetFormDate:

    $this->addOption('format', '%month%/%day%/%year%');
    $this->addOption('days', parent::generateTwoCharsRange(1, 31));
    $this->addOption('months', parent::generateTwoCharsRange(1, 12));
    $years = range(date('Y') - 5, date('Y') + 5);
    $this->addOption('years', array_combine($years, $years));

    As you can see, by default it allows all days, all months, and the previous 5 to next 5 years. All 3 field ranges can be customised with the options. So pick a range that works for you. Or, you can make it extra smart by adding a bit of custom code that, regardless of the range of years given, will always include one option for the year that is in the model (by reading $this->getObject()), so that you never get a blank year.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.