public function __invoke(Field $field, array $htmlAttributes = []) : string { $htmlAttributes['type'] = 'password'; $htmlAttributes['id'] = 'input.' . $field->getKey(); $htmlAttributes['name'] = $field->getKey(); $document = new DOMDocument('1.0', 'utf-8'); $input = $document->createElement('input'); $document->appendChild($input); $this->addAttributes($input, $htmlAttributes); return $document->saveHTML($input); }
public function __invoke(Field $field, array $htmlAttributes = []) : string { $htmlAttributes['id'] = 'input.' . $field->getKey(); $htmlAttributes['name'] = $field->getKey(); $document = new DOMDocument('1.0', 'utf-8'); $textarea = $document->createElement('textarea'); $textarea->appendChild($document->createTextNode($field->getValue())); $document->appendChild($textarea); $this->addAttributes($textarea, $htmlAttributes); return $document->saveHTML($textarea); }
public function __invoke(Field $field, array $htmlAttributes = []) : string { if (!array_key_exists('type', $htmlAttributes)) { $htmlAttributes['type'] = 'text'; } $htmlAttributes['id'] = 'input.' . $field->getKey(); $htmlAttributes['name'] = $field->getKey(); $htmlAttributes['value'] = $field->getValue(); $document = new DOMDocument('1.0', 'utf-8'); $input = $document->createElement('input'); $document->appendChild($input); $this->addAttributes($input, $htmlAttributes); return $document->saveHTML($input); }
public function __invoke(Field $field, array $options, array $htmlAttributes = []) : string { $htmlAttributes['id'] = 'input.' . $field->getKey(); if (array_key_exists('multiple', $htmlAttributes)) { $htmlAttributes['name'] = $field->getKey() . '[]'; $selectedValues = $field->getNestedValues(); } else { $htmlAttributes['name'] = $field->getKey(); $selectedValues = [$field->getValue()]; } $document = new DOMDocument('1.0', 'utf-8'); $select = $document->createElement('select'); $document->appendChild($select); $this->addAttributes($select, $htmlAttributes); $this->addOptions($document, $select, $options, $selectedValues); return $document->saveHTML($select); }
public function testGetNestedValues() { $field = new Field('foo', '', new FormErrorSequence(), Data::fromFlatArray(['foo[0]' => 'bar0', 'foo[1]' => 'bar1', 'foo[1][baz]' => 'bar2'])); $this->assertSame(['bar0', 'bar1'], $field->getNestedValues()); }