/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $this->element = new Element\Checkbox('foo'); $options = array('checked_value' => 'checked', 'unchecked_value' => 'unchecked'); $this->element->setOptions($options); $this->object = new FormCheckbox(); }
public function getElement() { $element = new Element\Checkbox('foo'); $options = array('checked_value' => 'checked', 'unchecked_value' => 'unchecked'); $element->setOptions($options); return $element; }
public function __construct() { parent::__construct(); $this->setAttribute('method', 'post'); $this->setAttribute('action', '/user/login'); $this->setAttribute('class', 'form'); $this->setAttribute('id', 'userLoginForm'); $this->setAttribute('role', 'form'); $email = new Email(); $email->setName('email')->setLabel('Email Address')->setAttribute('required', 'true'); $password = new Password(); $password->setName('password')->setLabel('Password')->setAttribute('required', 'true'); $csrf = new Csrf(); $csrf->setName('prev'); $checkbox = new Checkbox(); $checkbox->setName('remember-me'); $checkbox->setOptions(['use_hidden_element' => false, 'required' => false]); $checkbox->setChecked("checked"); $submit = new Submit(); $submit->setName('submit')->setValue('Sign In'); $this->add($email)->add($password)->add($checkbox)->add($csrf)->add($submit); foreach ($this->elements as $element) { if ($element instanceof Checkbox) { $element->setAttributes(['class' => 'custom-checkbox', 'data-toggle' => 'checkbox']); } else { if ($element instanceof Submit) { $element->setAttributes(['class' => 'btn-inverse btn-large', 'id' => 'loginSubmit']); } else { $element->setAttribute('class', 'form-control'); } } } }
public function __construct(LicenseInterface $license) { parent::__construct('license'); $agreement = $license->getAgreement() ?: $license->getTitle(); $checkbox = new Checkbox('agreement'); $checkbox->setOptions(['use_hidden_element' => false]); $checkbox->setLabel($agreement); $checkbox->setLabelOptions(['disable_html_escape' => true]); $this->add($checkbox); }
/** * Set options for an element. Accepted options are: * - label: label to associate with the element * - label_attributes: attributes to use when the label is rendered * - value_options: list of values and labels for the select options * * @param array|\Traversable $options * @return MultiCheckbox|ElementInterface * @throws Exception\InvalidArgumentException */ public function setOptions($options) { parent::setOptions($options); if (isset($this->options['value_options'])) { $this->setValueOptions($this->options['value_options']); } // Alias for 'value_options' if (isset($this->options['options'])) { $this->setValueOptions($this->options['options']); } return $this; }
/** * Set options for an element. Accepted options are: * - label: label to associate with the element * - label_attributes: attributes to use when the label is rendered * - value_options: list of values and labels for the select options * * @param array|\Traversable $options * @return MultiCheckbox|ElementInterface * @throws InvalidArgumentException */ public function setOptions($options) { parent::setOptions($options); if (isset($this->options['value_options'])) { $this->setValueOptions($this->options['value_options']); } // Alias for 'value_options' if (isset($this->options['options'])) { $this->setValueOptions($this->options['options']); } if (isset($this->options['disable_inarray_validator'])) { $this->setDisableInArrayValidator($this->options['disable_inarray_validator']); } return $this; }
/** * 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))); }
/** * Accepted options for MultiCheckbox: * - use_hidden_element: do we render hidden element? * - unchecked_value: value for checkbox when unchecked * - checked_value: value for checkbox when checked * * @param array|Traversable $options * @return Checkbox */ public function setOptions($options) { parent::setOptions($options); if (isset($options['use_hidden_element'])) { $this->setUseHiddenElement($options['use_hidden_element']); } if (isset($options['unchecked_value'])) { $this->setUncheckedValue($options['unchecked_value']); } if (isset($options['checked_value'])) { $this->setCheckedValue($options['checked_value']); } if (isset($options['listed_unchecked_value'])) { $this->setListedUncheckedValue($options['listed_unchecked_value']); } if (isset($options['listed_checked_value'])) { $this->setListedCheckedValue($options['listed_checked_value']); } return $this; }
public function testSetOptions() { $element = new CheckboxElement(); $element->setOptions(array('use_hidden_element' => true, 'unchecked_value' => 'foo', 'checked_value' => 'bar')); $this->assertEquals(true, $element->getOption('use_hidden_element')); $this->assertEquals('foo', $element->getOption('unchecked_value')); $this->assertEquals('bar', $element->getOption('checked_value')); }