In a Fieldset
I have an Element\Radio
foo
and Element\Text
bar
.
public function init()
{
$this->add(
[
'type' => 'radio',
'name' => 'foo',
'options' => [
'label' => _('foo'),
'value_options' => [
[
'value' => 'a',
'label' => 'a',
'selected' => true
],
[
'value' => 'b',
'label' => 'b'
]
]
]
...
]);
$this->add(
[
'name' => 'bar',
'type' => 'text',
'options' => [
'label' => 'bar',
...
],
...
]);
}
The validation of the field bar
is depending on the selected foo
option. It's easy to implement, if I can get the selected value of foo
:
public function getInputFilterSpecification()
{
return [
'bar' => [
'required' => $this->get('foo')->getCheckedValue() === 'a',
...
],
];
}
But there is no method Radio#getCheckedValue()
. Well, I can iterate over the $this->get('foo')->getOptions()['value_options']
, but is it really the only way?
How to get (in the Fieldset#getInputFilterSpecification()
) the selected option of a Zend\Form\Element\Radio
?