Example #1
0
 /**
  * Get validation attributes
  *
  * HTML5 spec: The first child option element of a select element with a required attribute and without a multiple attribute, and whose size is 1, must have either an empty value attribute, or must have no text content.
  * @see Ip\Form\Field.Field::getValidationAttributesStr()
  * @param string $doctype
  * @return string
  */
 public function getValidationAttributesStr($doctype)
 {
     $attributesStr = '';
     $values = $this->getValues();
     if (!isset($values[0])) {
         return parent::getValidationAttributesStr($doctype);
     }
     $firstValue = $values[0];
     if (is_array($firstValue)) {
         $key = $firstValue[0];
         $value = $firstValue[1];
     } else {
         $key = $firstValue;
         $value = $firstValue;
     }
     $html5Important = $doctype == \Ip\Response\Layout::DOCTYPE_HTML5 && $this->getAttribute('size') <= 1 && $this->getAttribute('multiple') === false && ($key != '' && $value != '');
     if (!$html5Important) {
         return parent::getValidationAttributesStr($doctype);
     }
     foreach ($this->getValidators() as $validator) {
         if (get_class($validator) == 'Ip\\Form\\Validator\\Required') {
             continue;
         }
         $tmpArgs = $validator->validatorAttributes();
         if ($tmpArgs != '') {
             $attributesStr .= ' ' . $tmpArgs;
         }
     }
     return $attributesStr;
 }