In my application, the user hsa to give a date by only selecting a month and a year in two dropdown lists. How can I achieve that?
Here is what I\'ve tried so far :
I working on a custom form type which would allow to solve such problem. The solution is based on what @oleg-andreyev proposed. The logic wrapped to a form type.
Usage:
add('exp_date', 'payum_credit_card_expiration_date');
The form type code:
vars['value'])) {
$view['day']->vars['value'] = $view['day']->vars['choices'][0]->value;
}
$style = 'display:none';
if (false == empty($view['day']->vars['attr']['style'])) {
$style = $view['day']->vars['attr']['style'].'; '.$style;
}
$view['day']->vars['attr']['style'] = $style;
}
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->replaceDefaults(array(
'years' => range(date('Y'), date('Y') + 9)
));
}
public function getParent()
{
return 'date';
}
public function getName()
{
return 'payum_credit_card_expiration_date';
}
}
You can copy\paste it or register payum bundle and use this type from (will be available there in next major release).