public function setAttribute($key, $value) { if ('value' === $key) { $this->selected = (int) $value; } parent::setAttribute($key, $value); }
/** * Handles the value attribute. If the "value" attribute is set, * the option with the attribute's value is then selected. * @param $name the name of the attribute * @param $value the value of the attribute */ public function setAttribute($name, $value) { if (strtolower($name) == 'value') { $this->setSelectedOption($value); } else { parent::setAttribute($name, $value); } }
/** * Handles the special case of label. The label is the inner text of the <option> tag. * @param $name The name of the attribute. * @param $value The value of the attribute. */ public function setAttribute($name, $value) { if ($name == 'label') { $this->setLabel((string) $value); } else { parent::setAttribute($name, $value); } }
public function addElement(Element $element) { $element->setForm($this); //If the element doesn't have a specified id, a generic identifier is applied. $id = $element->getAttribute("id"); $name = $element->getAttribute("name"); if (empty($id) && $name) { $element->setAttribute("id", $name); } elseif (empty($id)) { $element->setAttribute("id", $this->attributes["id"] . "-element-" . sizeof($this->elements)); } $this->elements[] = $element; /*For ease-of-use, the form tag's encytype attribute is automatically set if the File element class is added.*/ if ($element instanceof Element\File) { $this->attributes["enctype"] = "multipart/form-data"; } }
/** * Adds the functionality of setting the 'value' to the textarea's inner {@link TextNode}. * @param $attr the attribute name * @param $value the attribute value */ public function setAttribute($attr, $value) { //value is the text node //we add this for the sake of consistency amongst other form elements if (strtolower($attr) == 'value') { $this->setText($value); } else { parent::setAttribute($attr, $value); } }
/** Tests for {@link Element::setAttribute}. */ public function testSetAttribute() { $e = new Element('div'); $this->assertSame(0, count($e->getAttributes()), 'Set of attributes not empty for new Element.'); $e->setAttribute('lang', 'nl'); $a = $e->getAttributes(); $this->assertSame(1, count($a), 'Attribute not added to Element.'); $this->assertSame('nl', $a['lang'], 'Attribute value incorrect.'); $e->setAttribute('lang', 'nl-be'); $a = $e->getAttributes(); $this->assertSame(1, count($a), 'Attribute not replaced.'); $this->assertSame('nl-be', $a['lang'], 'Replaced attribute has incorrect value.'); }