/** * Contruir el control del typo pasado por parámetro * * @param string Tipo de control HTML. select|password|checkbox|input * @param string Nombre del control HTML. Etiqueta "name". * @param string Valor inicial del control HTML. Etiqueta "value". * @param array Atributos que se añaden a la etiqueta HTML del control. * @param array Opciones para un control HTML de tipo "select". * * @return Form */ private function buildControl($type, $name, $value = null, $attributes = array(), $options = array()) { switch ($type) { case 'select': //Agregar primero un valor vacio array_unshift($options, 'Seleccione un dato'); //Campo tipo select return $this->form->select($name, $options, $value, $attributes); case 'password': //Campo tipo password return $this->form->password($name, $attributes); case 'checkbox': //Campo tipo checkbox return $this->form->checkbox($name); case 'textarea': //Campo tipo area de texto return $this->form->textarea($name, $value, $attributes); case 'hidden': //Campo tipo hidden return $this->form->hidden($name, $value); default: //Por defecto, campo tipo input return $this->form->input($type, $name, $value, $attributes); } }
public function testCheckboxGeneration() { $result = $this->form->checkbox('foo'); $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'foo'))); $result = $this->form->checkbox('foo', array('checked' => false)); $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'foo'))); $result = $this->form->checkbox('foo', array('checked' => true)); $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'foo', 'checked' => 'checked'))); $result = $this->form->checkbox('foo', array('value' => true)); $this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'foo', 'checked' => 'checked'))); }
public function testCustomValueRadio() { $result = $this->form->radio('foo', array('value' => 'HERO')); $this->assertTags($result, array(array('input' => array('type' => 'radio', 'value' => 'HERO', 'name' => 'foo', 'id' => 'Foo')))); $result = $this->form->radio('foo', array('value' => 'nose')); $this->assertTags($result, array(array('input' => array('type' => 'radio', 'value' => 'nose', 'name' => 'foo', 'id' => 'Foo')))); $record = new Record(array('model' => $this->_model, 'data' => array('foo' => 'nose'))); $this->form->create($record); $result = $this->form->radio('foo', array('value' => 'nose')); $this->assertTags($result, array(array('input' => array('type' => 'radio', 'value' => 'nose', 'name' => 'foo', 'id' => 'MockFormPostFoo', 'checked' => 'checked')))); $record = new Record(array('model' => $this->_model, 'data' => array('foo' => 'foot'))); $this->form->create($record); $result = $this->form->checkbox('foo', array('value' => 'nose')); $this->assertTags($result, array(array('input' => array('type' => 'hidden', 'value' => '', 'name' => 'foo')), array('input' => array('type' => 'checkbox', 'value' => 'nose', 'name' => 'foo', 'id' => 'MockFormPostFoo')))); }