I have a moneyFieldset with two fields, amount and currency.
class MoneyFieldset ... { public function __construct($name = null, $options = array()) { parent::__construct($name, $options); $this->setHydrator(...); $this->add(array( 'name' => 'currency', 'type' => 'select', 'options' => array( 'value_options' => \Core\Service\Money::getAvailableCurrencies(true), ), 'attributes' => array( 'value' => \Core\Service\Money::DEFAULT_CURRENCY, ), )); $this->add(array( 'name' => 'amount', 'type' => 'text', )); } } public function getInputFilterSpecification() { $default = [ 'amount' => [ 'required' => false, 'allow_empty' => true, 'filters' => [ ['name' => AmountFilter::class] ], 'validators' => [ ] ], 'currency' => [ 'required' => false, 'allow_empty' => true, 'filters' => [ ['name' => StringToUpper::class] ], 'validators' => [ ] ] ]; return \Zend\Stdlib\ArrayUtils::merge($default, $this->filterSpec, true); }
I use moneyFieldset in my other fields, for example:
// Price Field $this->add(array( 'name' => 'price', 'type' => 'form.fieldset.moneyFieldset', 'attributes' => array( 'required' => true, 'invalidText' => 'Please type an amount' ), 'options' => array( ... ), ));
When I set the filter as follows:
function getInputFilterSpecification() { 'price' => [ 'required' => true, 'allow_empty' => false, ], }
This does not work because the price has 2 fields, so how can I say that the price [amount] and price [curreny] are not required?