Beispiel #1
0
 /**
  * @covers Xoops\Form\Select::render
  * @todo   Implement testRender().
  */
 public function testRender()
 {
     $this->object->addOptionArray(array('opt_key' => 'opt_name', 'opt_just_key' => null));
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<select'));
     $this->assertTrue(false !== strpos($value, 'name="name"'));
     $this->assertTrue(false !== strpos($value, 'size="1"'));
     $this->assertTrue(false !== strpos($value, 'title="Caption"'));
     $this->assertTrue(false !== strpos($value, 'id="name"'));
     $this->assertTrue(false !== strpos($value, '<option'));
     $this->assertTrue(false !== strpos($value, 'value="opt_key"'));
     $this->assertTrue(false !== strpos($value, '>opt_name</option>'));
     $this->assertTrue(false !== strpos($value, 'value="opt_just_key"'));
     $this->assertTrue(false !== strpos($value, '>opt_just_key</option>'));
     $this->object = new Select('Caption', 'name', 'value');
     // reset object
     $groups = array('grp_key' => 'grp_name', 'grp_key1' => 'grp_name1');
     $this->object->addOptgroup('opt_grp_name', $groups);
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<select'));
     $this->assertTrue(false !== strpos($value, 'name="name"'));
     $this->assertTrue(false !== strpos($value, 'size="1"'));
     $this->assertTrue(false !== strpos($value, 'title="Caption"'));
     $this->assertTrue(false !== strpos($value, 'id="name"'));
     $this->assertTrue(false !== strpos($value, '<optgroup'));
     $this->assertTrue(false !== strpos($value, 'label="opt_grp_name"'));
     $this->assertTrue(false !== strpos($value, '<option'));
     $this->assertTrue(false !== strpos($value, 'value="grp_key"'));
     $this->assertTrue(false !== strpos($value, '>grp_name</option>'));
     $this->assertTrue(false !== strpos($value, 'value="grp_key1"'));
     $this->assertTrue(false !== strpos($value, '>grp_name1</option>'));
 }
Beispiel #2
0
 public function render()
 {
     $name = $this->get('name');
     if (substr($name, -2) !== '[]') {
         $this->set('name', $name . '[]');
     }
     return parent::render();
 }
Beispiel #3
0
 /** @test */
 public function it_renders_with_options_the_full_html()
 {
     $field = new Select('test', 'Test', ['values' => ['miro' => 'test']]);
     $field->render();
     $options = $field->options();
     $this->assertCount(1, $options);
     $this->assertInstanceOf(Option::class, $options[0]);
 }
Beispiel #4
0
 public function render()
 {
     $options = [];
     foreach (range($this->min, $this->max) as $year) {
         $options[$year] = $year;
     }
     $this->setOptions($options);
     return parent::render();
 }
Beispiel #5
0
 public function render()
 {
     // check if we have options
     if ($this->options == null) {
         // if we don't have options, we set only 'yes' and 'no'
         $this->setOptions($this->getYesNo());
     } else {
         // if options is set, it means that a options['select'] is given
         // we combine it with yes/no
         $this->setOptions($this->options += $this->getYesNo());
     }
     return parent::render();
 }
Beispiel #6
0
 public function render()
 {
     $args = array();
     if (!empty($this->attributes['args'])) {
         $args = $this->attributes['args'];
     }
     $terms = get_terms($this->attributes['taxonomies'], $args);
     $options = array();
     if (!empty($this->attributes['options'])) {
         $options = $this->attributes['options'];
     }
     foreach ($terms as $term) {
         $options[$term->term_id] = $term->name;
     }
     $this->attributes['options'] = $options;
     parent::render();
 }
Beispiel #7
0
 /**
  * Representação textual da query
  *
  * @return string
  * */
 public function render()
 {
     return $this->_select->render();
 }
Beispiel #8
0
 /**
  * @param  string $name        The element name
  * @param  string $value       The time displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     // convert value to an array
     $default = array('hour' => null, 'minute' => null, 'second' => null);
     if (is_array($value)) {
         $value = array_merge($default, $value);
     } else {
         $value = ctype_digit($value) ? (int) $value : strtotime($value);
         if (false === $value) {
             $value = $default;
         } else {
             // int cast required to get rid of leading zeros
             $value = array('hour' => (int) date('H', $value), 'minute' => (int) date('i', $value), 'second' => (int) date('s', $value));
         }
     }
     $time = array();
     $emptyValues = $this->getOption('empty_values');
     // hours
     $widget = new Select(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['hour']) + $this->getOption('hours') : $this->getOption('hours')), array_merge($this->attributes, $attributes));
     $time['%hour%'] = $widget->render($name . '[hour]', $value['hour']);
     // minutes
     $widget = new Select(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['minute']) + $this->getOption('minutes') : $this->getOption('minutes')), array_merge($this->attributes, $attributes));
     $time['%minute%'] = $widget->render($name . '[minute]', $value['minute']);
     if ($this->getOption('with_seconds')) {
         // seconds
         $widget = new Select(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['second']) + $this->getOption('seconds') : $this->getOption('seconds')), array_merge($this->attributes, $attributes));
         $time['%second%'] = $widget->render($name . '[second]', $value['second']);
     }
     return strtr($this->getOption('with_seconds') ? $this->getOption('format') : $this->getOption('format_without_seconds'), $time);
 }
 /**
  * Display this class
  */
 private function prepareSmarty()
 {
     $this->smarty = new Template();
     $this->smarty->assign('heading', $this->file->filename);
     $this->smarty->assign('title', $this->file->filename);
     $this->smarty->assign('file', $this->file);
     $this->smarty->requireResource('file');
     $select = new Select('permission', '', FilePermissions::getAll());
     $select->selected_value = $this->file->permission;
     $this->smarty->assign('permission', $select->render());
 }
Beispiel #10
0
 /**
  * @covers Xoops\Form\Select::__construct
  * @covers Xoops\Form\Select::render
  * @covers Xoops\Form\Select::renderValidationJS
  */
 public function test__construct()
 {
     $oldWay = new Select('mycaption', 'myname', 'opt1');
     $oldWay->addOption('opt1', 'optname1');
     $oldWay->addOption('opt2', 'optname2');
     $newWay = new Select(['caption' => 'mycaption', 'name' => 'myname', 'value' => 'opt1', 'option' => ['opt1' => 'optname1', 'opt2' => 'optname2']]);
     $this->assertEquals($oldWay->render(), $newWay->render());
     $this->assertEquals($oldWay->renderValidationJS(), $newWay->renderValidationJS());
 }
 public function testInput()
 {
     $select = new Select(['name' => "name"]);
     $select->addOptions([1 => "Valor", 2 => "Valor 2"]);
     $this->assertEquals($select->render(), '<div><select name="name"><option value="1">Valor</option><option value="2">Valor 2</option></select></div>');
 }
Beispiel #12
0
 public function render()
 {
     $files = $this->getFiles();
     // set "images" hardcoded to identify the select options and append the Name
     parent::setID('images_' . $this->getNameWithoutBrackets());
     if (empty($files)) {
         $this->html = 'There are no images in "' . $this->getDirectory() . '" to select. Please upload some.';
     } else {
         $this->setOptions($files);
         // @todo first image is not displayed... display it.
         // Watch out!
         // the div images/preview must be present in the dom, before you assign js function to it via $('#image')
         $javascript = '<script type="text/javascript">
                        $(document).ready(function () {
                           $("#images_' . $this->getNameWithoutBrackets() . '").change(function () {
                                 var src = $("option:selected", this).val();
                                 $("#imagePreview_' . $this->getNameWithoutBrackets() . '").html(
                                     src ? "<img src=\'" + src + "\'>" : ""
                                 );
                             });
                         });
                         </script>';
         $html = parent::render() . CR . '<div id="imagePreview_' . $this->getNameWithoutBrackets() . '"></div>';
         $this->html = $html . $javascript;
     }
     return $this->html;
 }
Beispiel #13
0
 /**
  * @param string $name
  * @param string $value
  * @param array $options
  * @param array $attributes
  * @return string rendered widget
  */
 protected function renderYearWidget($name, $value, $options, $attributes)
 {
     $widget = new Select($options, $attributes);
     return $widget->render($name, $value);
 }
/**
 * Select getter Function
 * @see skip_select()
 * @ignore
 */
function get_select($name, $elements, $label = FALSE, $args = array(), $return = 'html')
{
    $select = new Select($name, $label, $args);
    if (count($elements) > 0) {
        if (is_array($elements)) {
            foreach ($elements as $element) {
                $select->add_element($element);
            }
        } else {
            $values = explode(',', $elements);
            foreach ($values as $value) {
                $select->add_element(array('value' => $value));
            }
        }
    }
    return $select->render();
}