Validator(Presence of ) not working properly for Phalcon\Forms\Element\Select !!

I had defined an array as input name for Phalcon\Forms\Element\Select...when i try to add PresenceOf validator to it....then even after selecting multiple values the validator is throwing error msgs..." Choose atleast one Wallet Types".

        $corporate_wallets = new Select('wallets_subscribed[]', $wallets, array(
            'multiple' => 'multiple',
            'useEmpty' => TRUE,
            'emptyText' => 'Select Wallets',
            'emptyValue' => '',
        ));
        $corporate_wallets->addValidators(array(
            new PresenceOf(array(
                'message' => 'Choose atleast one  Wallet Types'
                    ))
        ));
        $corporate_wallets->setAttribute('id', 'wallettypes');
        $corporate_wallets->setLabel('Select Wallet Types');
        $this->add($corporate_wallets);


6.7k
edited Feb '17

The PresenseOf validator is intended to work with text fields if you need them to be filled, e.g. name and email in user registration form. In this case you could use Numericallity validator if you have your $wallets array of kind:

$wallets = [1=>'wallet one', 2=>'wal two', 3=>'wal three'];

(in that case Select returns numeric value only if user had chosen any wallet.) Or you could write custom validator.

PS. You also could try InclusionIn validator, but I'm not sure if it will work with Select element.