I've used the f开发者_高级运维ormhelper in cakephp
echo $this->Form->input('birth_dt', array( 'label' => 'Date of birth'));
I found the day "31" in the month of February... is this a bug? because there is no such thing as february 31
Just like JohnP said, it won't change the dropdown based on the month value. I mean - you can use the FormHelper
without any Javascript in your project - so how would it do it anyway?
It would be a rather cool feature though. With the use of jQuery or whatever, you could listen to the month and year dropdowns, and change the options for the day dropdown based of the month/year value. cal_days_in_month(). Not too difficult to do, and I guess it could be included in Cake 2.0 as an additional feature of the FormHelper. As in, if you have the JsHelper
on - you can use it.
Well, just because I'm a little bit bored, I wrote this piece of jQuery
code:
<script type="text/javascript">
$().ready(function()
{
$('#ModelFieldMonth, #ModelFieldYear').change(function()
{
var day = $('#ModelFieldDay').val();
var month = $('#ModelFieldMonth').val();
var year = $('#ModelFieldYear').val();
var days_in_month = new Array();
days_in_month['01'] = 31; days_in_month['02'] = 28; days_in_month['03'] = 31; days_in_month['04'] = 30; days_in_month['05'] = 31; days_in_month['06'] = 30;
days_in_month['07'] = 31; days_in_month['08'] = 31; days_in_month['09'] = 30; days_in_month['10'] = 31; days_in_month['11'] = 30; days_in_month['12'] = 31;
if (year % 4 == 0) { days_in_month['02'] = 29; } // if leap year
$('#ModelFieldDay').find('option').remove();
var i = 0;
for (i = 1; i <= days_in_month[month]; i++)
{
$('#ModelFieldDay').append('<option value="'+i+'">'+i+'</option>')
}
$('#ModelFieldDay').val(day);
});
});
</script>
You're talking about the dropdowns right? Well, there's no such thing as April 31st either :)
The dropdowns just generate a list of all applicable dates for a given range. It doesn't change the value dependent on the month that is selected. So no, it's not a bug.
Like others have said, the dropdowns are static and not month specific. You should validate the date anyway before using it, so you can just add a validation rule to inform the user if they choose an invalid combination.
精彩评论