Reputation: 1654
I am making a date field like
->add('myDate','date',array(
'years' => range(date('Y')-50, date('Y')+20),
'widget' => 'choice',
'format' => 'yMMMd',
'days' => array(1),
'empty_value' => array('year'=>'Year', 'month'=> 'Month'),
'required' => false
))
Edit 1 :
Qus 1 - How to set the value for year and month option which has empty_text as Year and Month?
Qus 2 - Is there any way to add extra option in date field for month and year?
Edit 2 :
Using above paramter I am getting one of field Year like below
<select id="" name="" >
<option value="">Year</option>
<option value="1963">1963</option>
<option value="1964">1964</option>
</select>
and i want like below
<select id="" name="" >
<option value="0">Year</option> //value is 0
<option value="1963">1963</option>
<option value="1964">1964</option>
</select>
Apologize for my english
Upvotes: 1
Views: 398
Reputation: 1044
Do you want something like this -
<select id="" name="" >
<option value="0">Year</option> //value is 0
<option value="1963">1963</option>
<option value="1964">1964</option>
</select>
<select id="" name="" >
<option value="0">Month</option> //value is 0
<option value="1">1</option>
<option value="2">2</option>
.
.
.
</select>
<select id="" name="" >
<option value="0">Date</option> //value is 0
<option value="1">1</option>
<option value="2">2</option>
.
.
<option value="31">31</option>
</select>
Then I think create an object with the default date on object to the value you want. And then bind that object to the form. But I think it's gonna fail because I think it will give error if you try to create date object with date, month or year with value of 0.
Upvotes: 1