I wanted to bypass the annoying validation for the Select Element in Zend Framework 2. My requirement is that I have two select drop down boxes where I pass the values from the left select box to right select box and finally when I click the submit button, I post the values from right select box.
So basically the left select box is there to show the values to the user, my problem is that in the left select box as no value is selected it throws this error:
["selectAll"] => array(1) {
["isEmpty"] => string(36) "Value is required and can't be empty"
}
I have seen some old posts from Stackoverflow, where this is possible in Zend Framework 1 like one can disable the validation for the particular select element´
Examples:-
$selectAllElement->setRequired(false);
or
$selectAllElement->removeDecorator('Errors');
which some how these methods are not available in Zend Framework 2. In case if somebody has a solution of how disable the validation for a particular select element, please do share your knowledge, will be hepful for people getting into Zend Framework 2.
EDIT:
In my Form-
$select = new Element\Select('selectAllElement');
$select->setAttribute('title', 'Select a Value')
->setAttribute('id', 'id');
$options = array(
array(
//Fetching the values from database
),
);
$select->setAttribute('multiple', 'multiple')
->setAttribute('required', false)
->setValueOptions($options);
$this->add($select);
As per request from Sam, I have provided the code how I am adding the select element to my form and setting the attributes.
NOTE: I am not using any FIELDSETS
'required' => falsewithin validation configuration should be enough if i'm not mistaken. - SamsetRequired()is only for the HTML-Attributedrequired="(bool)"not for the validation required. Please see framework.zend.com/manual/2.0/en/modules/… for further details on inputFilters regarding Zend\Form - Sam'required' => falsein my inputFilter and now it is working. I have upvoted you since you gave your answers only in comments :) - user1686230