Ejemplo n.º 1
0
 /**
  *  @todo Document this method
  *
  */
 public function select_tag($name, $option_tags = null, $options = array(), $with_label = true)
 {
     if ($with_label) {
         $html = $this->make_label($name, $with_label);
     }
     if (is_array($option_tags)) {
         $option_tags = FormOptionsHelper::options_for_select($option_tags);
     } else {
         $option_tags = $option_tags;
     }
     return $html . $this->content_tag("select", $option_tags, array_merge(array("name" => $name, "id" => $name, "class" => "input_field select_field"), $this->convert_options($options)));
 }
Ejemplo n.º 2
0
 /**
  *  Test the options_for_select() method
  */
 public function testOptions_for_select_method()
 {
     //  Test choices with none selected
     $fo = new FormOptionsHelper();
     $this->assertEquals('<option value="0">foo</option>' . "\n" . '<option value="1">bar</option>', $fo->options_for_select(array('foo', 'bar')));
     //  Test choices with one selected
     $fo = new FormOptionsHelper();
     $this->assertEquals('<option value="0">mumble</option>' . "\n" . '<option value="1" selected="selected">grumble</option>', $fo->options_for_select(array('mumble', 'grumble'), 1));
 }
Ejemplo n.º 3
0
 public function test_should_remove_select_option_once_implicitly_set()
 {
     $Person = new MockAkActiveRecord($this);
     $FormOptionsHelper = new FormOptionsHelper();
     $FormOptionsHelper->addObject('person', $Person);
     $this->assertEqual(trim(str_replace("\n", '', $FormOptionsHelper->select('person', 'role', array('Admin' => 1, 'Moderator' => 2, 'Visitor' => 3), array('selected' => 2)))), '<select id="person_role" name="person[role]"><option value="1">Admin</option>' . '<option selected="selected" value="2">Moderator</option>' . '<option value="3">Visitor</option>' . '</select>');
 }
Ejemplo n.º 4
0
/**
 *  Create a new FormOptionsHelper object and call its options_for_select() method
 *
 *  @param string[]  List of choices
 *  @param integer   Index of the selected choice
 *  @uses FormOptionsHelper::options_for_select()
 */
function options_for_select($choices, $selected = null)
{
    $form = new FormOptionsHelper();
    return $form->options_for_select($choices, $selected);
}
Ejemplo n.º 5
0
 protected function make_time_select($shared_id, $selected_hour = false, $selected_minute = false)
 {
     for ($i = 0; $i <= 23; $i++) {
         $i = str_pad($i, 2, "0", STR_PAD_LEFT);
         $hour[$i] = $i;
     }
     for ($i = 0; $i <= 59; $i++) {
         $i = str_pad($i, 2, "0", STR_PAD_LEFT);
         $minute[$i] = $i;
     }
     if (!$selected_hour) {
         $selected_hour = date('G');
     }
     if (!$selected_minute) {
         $selected_minute = date('i');
     }
     $hour_options = FormOptionsHelper::options_for_select($hour, $selected_hour);
     $minute_options = FormOptionsHelper::options_for_select($minute, $selected_minute);
     $output .= $this->content_tag("select", $hour_options, array("id" => $shared_id . "_hour", "name" => $shared_id . "_hour", "onchange" => "{$shared_id}_set_date();"));
     $output .= $this->content_tag("select", $minute_options, array("id" => $shared_id . "_minute", "name" => $shared_id . "_minute", "onchange" => "{$shared_id}_set_date();"));
     return $output;
 }