Example #1
0
 public function getElementWithOptionSpec()
 {
     $element = new MultiCheckboxElement('foo');
     $options = array('This is the first label' => 'value1', 'This is the second label' => array('value' => 'value2', 'label' => 'This is the second label (overridden)', 'disabled' => false, 'label_attributes' => array('class' => 'label-class'), 'attributes' => array('class' => 'input-class')), 'This is the third label' => 'value3');
     $element->setAttribute('options', $options);
     return $element;
 }
Example #2
0
 /**
  * Load upload prevalue editor
  *
  * @return string
  */
 public function load()
 {
     $parameters = $this->getConfig();
     $elements = array();
     $optionsValues = !empty($parameters['options']) ? $parameters['options'] : array();
     $fieldset = new Fieldset('Available options');
     $element = new Element\MultiCheckbox('options');
     $element->setAttribute('selected', $optionsValues);
     $element->setAttribute('class', 'input-checkbox');
     $element->setValueOptions(array(array('value' => 'maxNumberOfFiles', 'label' => 'Is multiple', 'selected' => empty($optionsValues['maxNumberOfFiles']) ? false : true)));
     $fieldset->add($element);
     $elements[] = $fieldset;
     $element = new Element\MultiCheckbox('mime_list');
     $mimeList = array('image/gif', 'image/jpeg', 'image/png', 'image/tiff', 'image/svg+xml', 'text/css', 'text/csv', 'text/html', 'text/javascript', 'text/plain', 'text/xml', 'video/mpeg', 'video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/x-msvideo', 'video/x-flv', 'audio/mpeg', 'audio/x-ms-wma', 'audio/vnd.rn-realaudio', 'audio/x-wav');
     $options = array();
     foreach ($mimeList as $mime) {
         $options[] = array('value' => $mime, 'label' => $mime, 'selected' => !in_array($mime, empty($parameters['mime_list']) ? array() : $parameters['mime_list']) ? false : true);
     }
     $element->setValueOptions($options);
     $element->setAttribute('class', 'input-checkbox');
     $fieldset = new Fieldset('Mime list');
     $fieldset->add($element);
     $elements[] = $fieldset;
     return $this->addPath(__DIR__)->render('upload-prevalue.phtml', array('elements' => $elements));
 }
Example #3
0
 public function testAttributeType()
 {
     $element = new MultiCheckboxElement();
     $attributes = $element->getAttributes();
     $this->assertArrayHasKey('type', $attributes);
     $this->assertEquals('multi_checkbox', $attributes['type']);
 }
 /**
  * Renderiza apenas um value option
  *
  * @param MultiCheckboxElement $element
  * @param array                $option
  * @param boolean              $selected
  * @param array                $attributes
  * @return string
  */
 protected function renderOption(MultiCheckboxElement $element, array $option, $selected, array $attributes)
 {
     $globalLabelAttributes = $element->getLabelAttributes();
     $closingBracket = $this->getInlineClosingBracket();
     if (empty($globalLabelAttributes)) {
         $globalLabelAttributes = $this->labelAttributes;
     }
     $key = key($option);
     $optionSpec = current($option);
     $value = '';
     $disabled = false;
     $inputAttributes = $attributes;
     if (is_scalar($optionSpec)) {
         $optionSpec = ['value' => $key];
     }
     if (isset($optionSpec['value'])) {
         $value = $optionSpec['value'];
     }
     if (isset($optionSpec['selected'])) {
         $selected = $optionSpec['selected'];
     }
     if (isset($optionSpec['disabled'])) {
         $disabled = $optionSpec['disabled'];
     }
     if (isset($optionSpec['attributes'])) {
         $inputAttributes = array_merge($inputAttributes, $optionSpec['attributes']);
     }
     $inputAttributes['value'] = $value;
     $inputAttributes['checked'] = $selected;
     $inputAttributes['disabled'] = $disabled;
     $input = sprintf('<input %s%s', $this->createAttributesString($inputAttributes), $closingBracket);
     return $input;
 }
Example #5
0
 /**
  * @dataProvider multiCheckboxOptionsDataProvider
  */
 public function testInArrayValidationOfOptions($valueTests, $options)
 {
     $element = new MultiCheckboxElement('my-checkbox');
     $element->setAttributes(array('options' => $options));
     $inputSpec = $element->getInputSpecification();
     $this->assertArrayHasKey('validators', $inputSpec);
     $explodeValidator = $inputSpec['validators'][0];
     $this->assertInstanceOf('Zend\\Validator\\Explode', $explodeValidator);
     $this->assertTrue($explodeValidator->isValid($valueTests));
 }
Example #6
0
 /**
  * Load checkbox list editor
  *
  * @return Element\MultiCheckbox
  */
 public function load()
 {
     $parameters = $this->getConfig();
     $element = new Element\MultiCheckbox($this->getName());
     if (!empty($parameters)) {
         $element->setValueOptions($parameters);
     }
     $element->setLabel($this->getProperty()->getName())->setAttribute('id', $this->getName())->setAttribute('required', $this->getProperty()->isRequired())->setAttribute('class', 'input-checkbox')->setValue($this->getValue());
     return $element;
 }
Example #7
0
 public function testCanHandleMultiCheckboxesCorrectly()
 {
     $options = array('This is the first label' => 'value1', 'This is the second label' => 'value2', 'This is the third label' => 'value3');
     $element = new Element\MultiCheckbox('foo');
     $element->setAttribute('type', 'multi_checkbox');
     $element->setAttribute('options', $options);
     $element->setLabel('This is a multi-checkbox');
     $markup = $this->helper->render($element);
     $this->assertContains("<fieldset>", $markup);
     $this->assertContains("<legend>", $markup);
     $this->assertContains("<label>", $markup);
 }
Example #8
0
 /**
  * @dataProvider getMultiElements
  * @group multi
  */
 public function testRendersMultiElementsAsExpected($type, $inputType, $additionalMarkup)
 {
     $element = new Element\MultiCheckbox('foo');
     $element->setAttribute('type', $type);
     $element->setAttribute('options', array('value1' => 'option', 'value2' => 'label', 'value3' => 'last'));
     $element->setAttribute('value', 'value2');
     $markup = $this->helper->render($element);
     $this->assertEquals(3, substr_count($markup, '<' . $inputType), $markup);
     $this->assertContains($additionalMarkup, $markup);
     if ($type == 'select') {
         $this->assertRegexp('#value="value2"[^>]*?(selected="selected")#', $markup);
     }
 }
Example #9
0
 function __construct(array $associations = [])
 {
     parent::__construct('taxonomyTerm');
     $this->setAttribute('method', 'post');
     $filter = new InputFilter();
     $this->setInputFilter($filter);
     $this->add((new Text('destination'))->setAttribute('id', 'destination')->setAttribute('placeholder', 'ID (12345)')->setLabel('Move to:'));
     $multiCheckbox = new MultiCheckbox('associations');
     $multiCheckbox->setLabel('Elements')->setAttribute('id', 'associations');
     $multiCheckbox->setValueOptions($associations);
     $this->add($multiCheckbox);
     $this->add((new Submit('submit'))->setValue('Save')->setAttribute('class', 'btn btn-success pull-right'));
     $filter->add(['name' => 'destination', 'required' => true, 'allow_empty' => false, 'filters' => [['name' => 'Int']], 'validators' => [['name' => 'Digits']]]);
 }
Example #10
0
 public function __construct()
 {
     parent::__construct('AddRecipeForm');
     $noOfPeopleElement = new Text('NoOfPeople');
     $noOfPeopleElement->setLabel('Anzahl Personen');
     $this->add($noOfPeopleElement);
     // Add Text for kcal.
     //TODO: Rescrict input to integers
     $kcalElement = new Text('Kcal');
     $kcalElement->setLabel('Anzahl Kalorien');
     $this->add($kcalElement);
     // Add Checkbox for publicFlag
     $publicFlagElement = new Checkbox('PublicFlag');
     $publicFlagElement->setLabel('Möchten Sie das Rezept öffentlich speichern?');
     $this->add($publicFlagElement);
     $preparationTimeElement = new Text('PreparationTime');
     $preparationTimeElement->setLabel('Vorbereitungszeit');
     $this->add($preparationTimeElement);
     $cookingTimeElement = new Text('CookingTime');
     $cookingTimeElement->setLabel('Koch- / Backzeit');
     $this->add($cookingTimeElement);
     $restingTimeElement = new Text('RestingTime');
     $restingTimeElement->setLabel('Ruhezeit');
     $this->add($restingTimeElement);
     $types = $this->selectAllFrom('Types', 'Name');
     $typeElement = new MultiCheckbox('TypeId');
     $typeElement->setLabel('Rezept Typ');
     //$possibleValues = array('Sommermenu','Herbstmenu','Wintermenu','Frühlingsmenu');
     $typeElement->setValueOptions($types);
     $this->add($typeElement);
     $levels = $this->selectAllFrom('Levels', 'Shortname');
     $levelElement = new Select('Level');
     $levelElement->setLabel('Schwierigkeit');
     $levelElement->setValueOptions($levels);
     /*array('einfach','schwierig'));*/
     $levelElement->setValue($levels[0]);
     $this->add($levelElement);
     // Add steps
     $this->addSteps($this->getMaxNumberOfSteps());
     // Add select for chosing how many steps should be displayed
     $stepNumbers = range(1, $this->maxNoOfSteps);
     $addStepSelect = new Select('StepNumber');
     $addStepSelect->setLabel('Anzahl Schritte wählen');
     $addStepSelect->setValueOptions($stepNumbers);
     $addStepSelect->setAttribute('id', 'NoOfStepSelect');
     $addStepSelect->setAttribute('onchange', 'show(++this.value)');
     $this->add($addStepSelect);
 }
Example #11
0
 /**
  * {@inheritDoc}
  */
 public function getLabel()
 {
     if (null === $this->label) {
         $this->label = __('Roles');
     }
     return parent::getLabel();
 }
Example #12
0
 /**
  * Load upload prevalue editor
  *
  * @return Element\Checkbox[]
  */
 public function load()
 {
     $config = $this->getConfig();
     $isMultiple = new Element\Checkbox('is_multiple');
     $isMultiple->setAttributes(array('value' => isset($config['is_multiple']) ? $config['is_multiple'] : '', 'class' => 'input-checkbox', 'id' => 'is_multiple'));
     $isMultiple->setOptions(array('label' => 'Is Multiple', 'label_attributes' => array('class' => 'required control-label col-lg-2')));
     $mimeList = new Element\MultiCheckbox('mime_list');
     $array = array('image/gif', 'image/jpeg', 'image/png', 'image/tiff', 'image/svg+xml', 'text/css', 'text/csv', 'text/html', 'text/javascript', 'text/plain', 'text/xml', 'video/mpeg', 'video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/x-msvideo', 'video/x-flv', 'audio/mpeg', 'audio/x-ms-wma', 'audio/vnd.rn-realaudio', 'audio/x-wav');
     $options = array();
     foreach ($array as $mime) {
         $options[] = array('value' => $mime, 'label' => $mime, 'selected' => !in_array($mime, empty($config['mime_list']) ? array() : $config['mime_list']) ? false : true);
     }
     $mimeList->setAttribute('class', 'input-checkbox');
     $mimeList->setValueOptions($options);
     return array($isMultiple, $this->addPath(__DIR__)->render('upload-prevalue.phtml', array('mimeList' => $mimeList)));
 }
 /**
  * @param array|\Traversable $options
  */
 public function setOptions($options)
 {
     if (isset($options['subscriber_id'])) {
         $this->subscriberId = $options['subscriber_id'];
     }
     if (isset($options['include_hidden'])) {
         $this->setIncludeHidden($options['include_hidden']);
     }
     parent::setOptions($options);
 }
 public function __construct()
 {
     $dbAdapter = Zend\Db\TableGateway\Feature\GlobalAdapterFeature::getStaticAdapter();
     $this->setDbAdapter($dbAdapter);
     parent::__construct('recipefieldset');
     $this->add(array('name' => 'noOfPeople', 'type' => 'Text', 'options' => array('label' => 'Anzahl Personen')));
     // Add Text for kcal.
     //TODO: Rescrict input to integers
     $kcalElement = new Text('kcal');
     $kcalElement->setLabel('Anzahl Kalorien');
     $this->add($kcalElement);
     // Add Checkbox for publicFlag
     $publicFlagElement = new Checkbox('publicFlag');
     $publicFlagElement->setLabel('Möchten Sie das Rezept öffentlich speichern?');
     $this->add($publicFlagElement);
     $typeElement = new MultiCheckbox('typeId');
     $typeElement->setLabel('Rezept Typ');
     $possibleValues = array('Sommermenu', 'Herbstmenu', 'Wintermenu', 'Frühlingsmenu');
     $typeElement->setValueOptions($possibleValues);
     $this->add($typeElement);
     $selectString = 'SELECT * FROM Levels';
     //$select->getSqlString();
     $result = $dbAdapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
     $levels = array();
     foreach ($result as $row) {
         $levels[] = $row['Shortname'];
     }
     $levelElement = new Select('level');
     $levelElement->setLabel('Schwierigkeit');
     $levelElement->setValueOptions($levels);
     /*array('einfach','schwierig'));*/
     $this->add($levelElement);
     // Add steps
     $this->addSteps(4);
     $stepNumbers = range(1, $this->maxNoOfSteps);
     $addStepSelect = new Select('stepNumber');
     $addStepSelect->setLabel('Anzahl Schritte wählen');
     $addStepSelect->setValueOptions($stepNumbers);
     $addStepSelect->setAttribute('id', 'noOfStepSelect');
     $addStepSelect->setAttribute('onchange', 'show()');
     $this->add($addStepSelect);
 }
 /**
  * {@inheritDoc}
  */
 public function setValue($value)
 {
     if ($value instanceof \Traversable) {
         $value = ArrayUtils::iteratorToArray($value);
     } elseif ($value == null) {
         return parent::setValue(array());
     } elseif (!is_array($value)) {
         $value = (array) $value;
     }
     return parent::setValue(array_map(array($this->getProxy(), 'getValue'), $value));
 }
Example #16
0
 public function __construct(array $roles)
 {
     parent::__construct();
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'panel-body');
     $name = new Text('name');
     $name->setLabel('name');
     $name->setAttribute('class', 'form-control');
     $this->add($name);
     $parent = new MultiCheckbox('parent');
     $parent->setLabel('parent');
     $parent->setUseHiddenElement(true);
     $parent->setValueOptions($roles);
     $this->add($parent);
     $this->getInputFilter()->get($parent->getName())->setAllowEmpty(true);
     $submit = new Submit('save');
     $submit->setValue('save');
     $submit->setAttribute('class', 'btn btn-primary');
     $this->add($submit);
 }
Example #17
0
 /**
  * @dataProvider useHiddenAttributeDataProvider
  */
 public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttributes($useHiddenElement)
 {
     $element = new MultiCheckboxElement();
     $options = array('1' => 'Option 1', '2' => 'Option 2', '3' => 'Option 3');
     $element->setAttributes(array('options' => $options));
     $element->setUseHiddenElement($useHiddenElement);
     $inputSpec = $element->getInputSpecification();
     $this->assertArrayHasKey('validators', $inputSpec);
     $this->assertInternalType('array', $inputSpec['validators']);
     $expectedClasses = array('Zend\\Validator\\Explode');
     foreach ($inputSpec['validators'] as $validator) {
         $class = get_class($validator);
         $this->assertTrue(in_array($class, $expectedClasses), $class);
         switch ($class) {
             case 'Zend\\Validator\\Explode':
                 $inArrayValidator = $validator->getValidator();
                 $this->assertInstanceOf('Zend\\Validator\\InArray', $inArrayValidator);
                 $values = array_values($options);
                 if ($element->useHiddenElement()) {
                     $values[] = $element->getUncheckedValue();
                 }
                 $this->assertEquals($values, $inArrayValidator->getHaystack());
                 break;
             default:
                 break;
         }
     }
 }
Example #18
0
 public function formAction()
 {
     // Build a name element.
     $name = new Element('name');
     $name->setLabel('Your name');
     $name->setAttributes(array('type' => 'text'));
     // Build a submit button element.
     $send = new Element('send');
     $send->setLabel('Send');
     $send->setAttributes(array('type' => 'submit', 'value' => 'Send'));
     // Build a checkbox element.
     $check = new Checkbox('check');
     $check->setLabel('Checkbox example');
     // Build a multi-checkbox element.
     $multicheck = new MultiCheckbox('multicheck');
     $multicheck->setLabel('Multi checkbox example');
     $multicheck->setOptions(array('value_options' => array('One' => 'one', 'Two' => 'two')));
     // Assemble the form.
     $form = new Form('contact');
     $form->add($name);
     $form->add($check);
     $form->add($multicheck);
     $form->add($send);
     // Get the request if any.
     $request = $this->getRequest();
     $data = $request->getPost();
     $form->setData($data);
     // Validate the form
     if ($form->isValid()) {
         $validatedData = $form->getData();
         $success = 'Form submit was successful';
     } else {
         $success = 'Form submit failed';
         $messages = $form->getMessages();
     }
     // Set the method attribute for the form
     $form->setAttribute('method', 'post');
     return new ViewModel(array('form' => $form, 'success' => $success, 'messages' => $messages, 'data' => $data));
 }
Example #19
0
 protected function addMultiCheckbox($name, $label, array $data)
 {
     $multiCheckbox = new Element\MultiCheckbox($name);
     $multiCheckbox->setLabel($label);
     $multiCheckbox->setLabelAttributes(array('class' => "col-sm-{$this->labelWidth}"));
     $multiCheckbox->setValueOptions($data);
     $multiCheckbox->setOption('column-size', "sm-{$this->controlWidth}");
     $multiCheckbox->setOption('inline', true);
     $this->add($multiCheckbox);
     return $this;
 }
 /**
  * @param TableModel $table
  */
 public function __construct(TableModel $table)
 {
     parent::__construct('Display');
     $this->tableModel = $table;
     $tableHeaders = $this->tableModel->getTableHeaders();
     // Group checkboxes by property
     $columnGroups = array();
     foreach ($tableHeaders as $tableHeader) {
         /** @var TableHeaderCellModel $tableHeader */
         $columnNameSegments = explode('.', $tableHeader->getName());
         if (!array_key_exists($columnNameSegments[0], $columnGroups)) {
             $columnGroups[$columnNameSegments[0]] = array();
         }
     }
     // Create all values for each property
     foreach ($tableHeaders as $tableHeader) {
         $columnNameSegments = explode('.', $tableHeader->getName());
         $label = $tableHeader->getName();
         if (count($columnNameSegments) > 1) {
             $segments = $columnNameSegments;
             unset($segments[0]);
             $label = implode('.', $segments);
         }
         $valueOption = array('value' => $tableHeader->getName(), 'label' => $label, 'selected' => $tableHeader->isVisible());
         $columnGroups[$columnNameSegments[0]][] = $valueOption;
     }
     // Create the actual form element per property
     foreach ($columnGroups as $property => $checkboxValues) {
         $multiCheckbox = new MultiCheckbox($this->checkboxName);
         $multiCheckbox->setOptions(array('inline' => false, 'value_options' => $checkboxValues));
         $isParentField = strpos($checkboxValues[0]['value'], ".") !== false;
         if (count($checkboxValues) >= 2 || count($checkboxValues) == 1 && $isParentField) {
             $multiCheckbox->setLabel($property);
         }
         // Dirty hack, because this->add() does not detect element or fieldset naming conflicts
         $this->iterator->insert($property, $multiCheckbox, 0);
     }
     $this->add(array('name' => 'submit', 'type' => 'submit', 'label' => '<span class="glyphicon glyphicon glyphicon-refresh"></span>', 'attributes' => array('value' => 'Apply', 'class' => 'btn knopSearch')));
 }
Example #21
0
 /**
  * Load Image cropper prevalue editor
  *
  * @return string
  */
 public function load()
 {
     $config = $this->getConfig();
     $resizeOption = new Element\Select('resize_option');
     $resizeOption->setValue(empty($config['resize_option']) ? 'auto' : $config['resize_option'])->setAttribute('class', 'form-control')->setAttribute('id', 'resize-option')->setLabel('Resize option')->setLabelAttributes(array('class' => 'col-lg-2'))->setValueOptions(array('auto' => 'auto', 'crop' => 'crop'));
     $backgroundOption = new Element\Text('background');
     $backgroundOption->setValue(empty($config['background']) ? '' : $config['background'])->setAttribute('class', 'form-control')->setAttribute('id', 'background')->setLabel('Background color')->setLabelAttributes(array('class' => 'col-lg-2'));
     $mimeList = new Element\MultiCheckbox('mime_list');
     $mimeList->setAttribute('class', 'input-checkbox')->setLabel('Mime list')->setLabelAttributes(array('class' => 'col-lg-2'));
     $array = array('image/gif', 'image/jpeg', 'image/png');
     $options = array();
     foreach ($array as $mime) {
         $options[] = array('value' => $mime, 'label' => $mime, 'selected' => !in_array($mime, empty($config['mime_list']) ? array() : $config['mime_list']) ? false : true);
     }
     $mimeList->setValueOptions($options);
     $sizeElements = array();
     $idx = 0;
     if (!empty($config['size'])) {
         foreach ($config['size'] as $idx => $size) {
             $elementSizeName = new Element\Text('size[' . $idx . '][name]');
             $elementSizeName->setValue($size['name'])->setAttribute('class', 'form-control')->setAttribute('id', 'name' . $idx)->setLabel('Name');
             $elementWidth = new Element\Text('size[' . $idx . '][width]');
             $elementWidth->setValue($size['width'])->setAttribute('class', 'form-control')->setAttribute('id', 'width' . $idx)->setLabel('Width');
             $elementHeight = new Element\Text('size[' . $idx . '][height]');
             $elementHeight->setValue($size['height'])->setAttribute('class', 'form-control')->setAttribute('id', 'height' . $idx)->setLabel('Height');
             $sizeElements[] = array($elementSizeName, $elementWidth, $elementHeight);
         }
         $idx++;
     }
     $elementSizeName = new Element\Text('size[#{idx}][name]');
     $elementSizeName->setAttribute('id', 'name#{idx}')->setAttribute('class', 'form-control')->setLabel('Name');
     $elementWidth = new Element\Text('size[#{idx}][width]');
     $elementWidth->setLabel('Width')->setAttribute('class', 'form-control')->setAttribute('id', 'width#{idx}');
     $elementHeight = new Element\Text('size[#{idx}][height]');
     $elementHeight->setLabel('Height')->setAttribute('class', 'form-control')->setAttribute('id', 'height#{idx}');
     $template = array($elementSizeName, $elementWidth, $elementHeight);
     return $this->addPath(__DIR__)->render('upload-prevalue.phtml', array('elements' => array('resize-option' => $resizeOption, 'background' => $backgroundOption, 'mime' => $mimeList, 'size' => $sizeElements, 'size-template' => $template)));
 }
 /**
  * Render a hidden element for empty/unchecked value
  *
  * @param  MultiCheckboxElement $element
  * @param  array                $attributes
  * @return string
  */
 protected function renderHiddenElement(MultiCheckboxElement $element, array $attributes)
 {
     $closingBracket = $this->getInlineClosingBracket();
     $uncheckedValue = $element->getUncheckedValue() ? $element->getUncheckedValue() : $this->uncheckedValue;
     $hiddenAttributes = array('name' => $element->getName(), 'value' => $uncheckedValue);
     return sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket);
 }
Example #23
0
 public function testShowErrorInMultiCheckbox()
 {
     $element = new Element\MultiCheckbox('hobby');
     $element->setLabel("Hobby");
     $element->setValueOptions(array('0' => 'working', '1' => 'coding'));
     $element->setMessages(array('Error message'));
     $markup = $this->helper->__invoke($element);
     $this->assertContains('<ul><li>Error message</li></ul>', $markup);
 }
Example #24
0
 /**
  * Render options
  *
  * @param  MultiCheckboxElement $element
  * @param  array                $options
  * @param  array                $selectedOptions
  * @param  array                $attributes
  * @return string
  */
 protected function renderOptions(MultiCheckboxElement $element, array $options, array $selectedOptions, array $attributes)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $labelClose = $labelHelper->closeTag();
     $labelPosition = $this->getLabelPosition();
     $globalLabelAttributes = $element->getLabelAttributes();
     $closingBracket = $this->getInlineClosingBracket();
     if (empty($globalLabelAttributes)) {
         $globalLabelAttributes = $this->labelAttributes;
     }
     $combinedMarkup = array();
     $count = 0;
     foreach ($options as $key => $optionSpec) {
         $count++;
         if ($count > 1 && array_key_exists('id', $attributes)) {
             unset($attributes['id']);
         }
         $value = '';
         $label = '';
         $inputAttributes = $attributes;
         $labelAttributes = $globalLabelAttributes;
         $selected = isset($inputAttributes['selected']) && $inputAttributes['type'] != 'radio' && $inputAttributes['selected'] != false ? true : false;
         $disabled = isset($inputAttributes['disabled']) && $inputAttributes['disabled'] != false ? true : false;
         if (is_scalar($optionSpec)) {
             $optionSpec = array('label' => $optionSpec, 'value' => $key);
         }
         if (isset($optionSpec['value'])) {
             $value = $optionSpec['value'];
         }
         if (isset($optionSpec['label'])) {
             $label = $optionSpec['label'];
         }
         if (isset($optionSpec['selected'])) {
             $selected = $optionSpec['selected'];
         }
         if (isset($optionSpec['disabled'])) {
             $disabled = $optionSpec['disabled'];
         }
         if (isset($optionSpec['label_attributes'])) {
             $labelAttributes = isset($labelAttributes) ? array_merge($labelAttributes, $optionSpec['label_attributes']) : $optionSpec['label_attributes'];
         }
         if (isset($optionSpec['attributes'])) {
             $inputAttributes = array_merge($inputAttributes, $optionSpec['attributes']);
         }
         if (in_array($value, $selectedOptions)) {
             $selected = true;
         }
         $inputAttributes['value'] = $value;
         $inputAttributes['checked'] = $selected;
         $inputAttributes['disabled'] = $disabled;
         $input = sprintf('<input %s%s', $this->createAttributesString($inputAttributes), $closingBracket);
         if (null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
         $label = $escapeHtmlHelper($label);
         $labelCombined = $labelHelper->openTag(array('class' => 'choice')) . $label . $labelClose;
         switch ($labelPosition) {
             case self::LABEL_PREPEND:
                 $markup = $labelCombined . $input;
                 break;
             case self::LABEL_APPEND:
             default:
                 $markup = $input . $labelCombined;
                 break;
         }
         $combinedMarkup[] = $markup;
     }
     return implode($this->getSeparator(), $combinedMarkup);
 }
Example #25
0
 public function testSetOptionsOptions()
 {
     $element = new MultiCheckboxElement();
     $element->setOptions(array('value_options' => array('bar' => 'baz'), 'options' => array('foo' => 'bar')));
     $this->assertEquals(array('bar' => 'baz'), $element->getOption('value_options'));
     $this->assertEquals(array('foo' => 'bar'), $element->getOption('options'));
 }
 public function testGetSelectedAttributeForGroupReturnTrue()
 {
     $element = new MultiCheckboxElement('foo');
     $element->setAttribute('selected', 'true');
     $element->setValueOptions(array(array('label' => 'label1', 'value' => 'value1')));
     $markup = $this->helper->render($element);
     $this->assertRegexp('#value="value1" checked="checked"#', $markup);
 }
 /**
  * @see \Zend\Form\View\Helper\FormMultiCheckbox::renderOptions()
  * @param \Zend\Form\Element\MultiCheckbox $oElement
  * @param array $aOptions
  * @param array $aSelectedOptions
  * @param array $aAttributes
  * @return string
  */
 protected function renderOptions(\Zend\Form\Element\MultiCheckbox $oElement, array $aOptions, array $aSelectedOptions, array $aAttributes)
 {
     $iIterator = 0;
     $aGlobalLabelAttributes = $oElement->getLabelAttributes() ?: $this->labelAttributes;
     $sMarkup = '';
     $oLabelHelper = $this->getLabelHelper();
     foreach ($aOptions as $key => $aOptionspec) {
         if (is_scalar($aOptionspec)) {
             $aOptionspec = array('label' => $aOptionspec, 'value' => $key);
         }
         $iIterator++;
         if ($iIterator > 1 && array_key_exists('id', $aAttributes)) {
             unset($aAttributes['id']);
         }
         //Option attributes
         $aInputAttributes = $aAttributes;
         if (isset($aOptionspec['attributes'])) {
             $aInputAttributes = \Zend\Stdlib\ArrayUtils::merge($aInputAttributes, $aOptionspec['attributes']);
         }
         //Option value
         $aInputAttributes['value'] = isset($aOptionspec['value']) ? $aOptionspec['value'] : '';
         //Selected option
         if (in_array($aInputAttributes['value'], $aSelectedOptions)) {
             $aInputAttributes['checked'] = true;
         } elseif (isset($aOptionspec['selected'])) {
             $aInputAttributes['checked'] = !!$aOptionspec['selected'];
         } else {
             $aInputAttributes['checked'] = isset($aInputAttributes['selected']) && $aInputAttributes['type'] !== 'radio' && $aInputAttributes['selected'] != false;
         }
         //Disabled option
         if (isset($aOptionspec['disabled'])) {
             $aInputAttributes['disabled'] = !!$aOptionspec['disabled'];
         } else {
             $aInputAttributes['disabled'] = isset($aInputAttributes['disabled']) && $aInputAttributes['disabled'] != false;
         }
         //Render option
         $sOptionMarkup = sprintf('<input %s%s', $this->createAttributesString($aInputAttributes), $this->getInlineClosingBracket());
         //Option label
         $sLabel = isset($aOptionspec['label']) ? $aOptionspec['label'] : '';
         if ($sLabel) {
             $aLabelAttributes = $aGlobalLabelAttributes;
             if (isset($aOptionspec['label_attributes'])) {
                 $aLabelAttributes = isset($aLabelAttributes) ? array_merge($aLabelAttributes, $aOptionspec['label_attributes']) : $aOptionspec['label_attributes'];
             }
             if (null !== ($oTranslator = $this->getTranslator())) {
                 $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain());
             }
             switch ($this->getLabelPosition()) {
                 case self::LABEL_PREPEND:
                     $sOptionMarkup = sprintf($oLabelHelper->openTag($aLabelAttributes) . '%s%s' . $oLabelHelper->closeTag(), $this->getEscapeHtmlHelper()->__invoke($sLabel), $sOptionMarkup);
                     break;
                 case self::LABEL_APPEND:
                 default:
                     $sOptionMarkup = sprintf($oLabelHelper->openTag($aLabelAttributes) . '%s%s' . $oLabelHelper->closeTag(), $sOptionMarkup, $this->getEscapeHtmlHelper()->__invoke($sLabel));
                     break;
             }
         }
         $sMarkup .= ($sMarkup ? $this->getSeparator() : '') . $sOptionMarkup;
     }
     return $sMarkup;
 }
 /**
  * Iterates through the value_options & set the value option's appropriate class
  *
  * @param Element\MultiCheckbox $element
  * @return array
  */
 public function setOptionLabelAttributes(Element\MultiCheckbox $element)
 {
     $valueOptions = $element->getValueOptions();
     $elementClass = array_pop(explode('\\', get_class($element)));
     $labelClass = '';
     foreach ($valueOptions as $key => $spec) {
         if (!is_array($spec)) {
             continue;
         }
         if (!isset($spec['label_attributes'])) {
             $spec['label_attributes'] = array('class' => '');
         }
         if (is_scalar($spec['label_attributes'])) {
             $spec['label_attributes'] = array($spec['label_attributes']);
         }
         if (!isset($spec['label_attributes']['class'])) {
             $spec['label_attributes']['class'] = '';
         }
         switch ($elementClass) {
             case 'MultiCheckbox':
                 $labelClass = 'checkbox';
                 break;
             case 'Radio':
                 $labelClass = 'radio';
                 break;
         }
         $class = strstr($spec['label_attributes']['class'], $labelClass) === false ? ' ' . $labelClass : '';
         $spec['label_attributes']['class'] = trim($spec['label_attributes']['class'] . $class);
         $valueOptions[$key] = $spec;
     }
     return $valueOptions;
 }
 /**
  * {@inheritDoc}
  */
 public function setValue($value)
 {
     return parent::setValue($this->getProxy()->getValue($value));
 }
Example #30
0
 /**
  * Builds fieldset with additional properties for the "monthly" repeat picker value.
  * It returns the built fieldset (used as a child of the "repeat" fieldset).
  * 
  * @return Fieldset
  */
 public function getRepeatMonthlyFieldset()
 {
     $repeatMonthlyFieldset = new Fieldset(self::MONTHLY);
     // Note that this field is rendered on the frontend without the view helper,
     // for more flexibility.
     $dayOfMonth = new Element\MultiCheckbox('dayOfMonth');
     $dayOfMonth->setLabel('Pick days');
     $dayOfMonth->setValueOptions(array_combine(range(1, 31), range(1, 31)));
     $repeatMonthlyFieldset->add($dayOfMonth);
     return $repeatMonthlyFieldset;
 }