/** * Método construtor * @param string $name Nome do campo * @param string $value Valor do campo * @param string $label Legenda do campo */ public function __construct($name, $value, $label) { parent::setName($name); parent::setValue($value); parent::setLabel($label); parent::setType('text'); }
public function testVerificaSeOsDadosForamInseridos() { $input = new Input(); $input->setType("text"); $input->setId("inputUsuario"); $input->setName("usuario"); $input->setClass("form-control"); $input->setProtected("protected"); $input->setLabel("Usuário"); $input->setAlert("Erro no field."); $input->setValue("valor"); $this->assertEquals("text", $input->getType()); $this->assertEquals("inputUsuario", $input->getId()); $this->assertEquals("usuario", $input->getName()); $this->assertEquals("form-control", $input->getClass()); $this->assertEquals("protected", $input->getProtected()); $this->assertEquals("Usuário", $input->getLabel()); $this->assertEquals("Erro no field.", $input->getAlert()); $this->assertEquals("valor", $input->getValue()); }
/** * @param string|array $_choice * @param string $_value * * @return $this */ public function addChoice($_choice, $_value = null) { if (is_array($_choice)) { $text = array_get($_choice, 'label'); $value = array_get($_choice, 'value'); $atts = array_except($_choice, ['label']); } else { $text = $_choice; $value = is_null($_value) ? $_choice : $_value; $atts = ['value' => $value]; } if (!isset($atts['id'])) { $atts['id'] = $this->id . '-' . $this->choices->count(); } $choice = new Input($this->type, $this->name, $value, $atts); $choice->inputCheckable = true; $choice->setAttribute('type', $this->type); if ($this->isSelected($value)) { $choice->setAttribute('checked', 'checked'); } $choice->addClass($this->type); $choice->setLabel($text); $choice->setContainer(null); $this->choices->push($choice); return $this; }