AutocompleterTextfield: Unterschied zwischen den Versionen
Aus Contao Community Documentation
Psi (Diskussion | Beiträge) |
Psi (Diskussion | Beiträge) |
||
| Zeile 1: | Zeile 1: | ||
| + | [[Category:Dev_HOWTOS]] | ||
| + | [[Category:Development]] | ||
[[Category:Extensions]] | [[Category:Extensions]] | ||
{{ExtInfo | {{ExtInfo | ||
| Zeile 9: | Zeile 11: | ||
}} | }} | ||
'''SVN''': http://svn.4wardmedia.de/autocompleterTextfield | '''SVN''': http://svn.4wardmedia.de/autocompleterTextfield | ||
| + | |||
| + | =AutocompleterTextfield= | ||
[[Datei:AutocompleterTextfield.png]] | [[Datei:AutocompleterTextfield.png]] | ||
| − | Autocompleting für ein Textfeld anhand von ''options'', ''options_callback'' oder ''foreignKey''. | + | Autocompleting für ein Textfeld anhand von ''options'', ''options_callback'' oder ''foreignKey''. |
Über die Eval-Option ''storeId'' kann die ID bzw. der Array-Key anstatt der Textwert gespeichert werden. | Über die Eval-Option ''storeId'' kann die ID bzw. der Array-Key anstatt der Textwert gespeichert werden. | ||
| Zeile 64: | Zeile 68: | ||
), | ), | ||
), | ), | ||
| + | </source> | ||
| + | |||
| + | |||
| + | ==Beispiel für einen options_callback== | ||
| + | Falls die POST-Variable ("value") gesetzt ist, kann eine Vorselektierung stattfinden. Sie wird vom Autocompleter-Javascript übermittelt und enthält den eingegebenen String. | ||
| + | <source lang="php"> | ||
| + | public function getProducts() | ||
| + | { | ||
| + | $this->import('Database'); | ||
| + | |||
| + | // perhaps do some validation, cause POST-Vars are evil | ||
| + | if($this->Input->post('value')) | ||
| + | { | ||
| + | $objProducts = $this->Database->prepare(' SELECT id,name | ||
| + | FROM tl_product | ||
| + | WHERE name LIKE ? | ||
| + | ORDER BY name') | ||
| + | ->execute('%'.$this->Input->post('value').'%'); | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | $objProducts = $this->Database->prepare(' SELECT id,name | ||
| + | FROM tl_product | ||
| + | ORDER BY name') | ||
| + | ->execute(); | ||
| + | } | ||
| + | $prods = array(); | ||
| + | while($objProducts->next()) $prods[$objProducts->id] = $objProducts->name; | ||
| + | return $prods; | ||
| + | } | ||
</source> | </source> | ||
Version vom 28. Oktober 2011, 15:23 Uhr
| Erweiterungs-Übersicht | |
|---|---|
| Entwickler Webseite | http://www.4wardmedia.de.de |
| Version der Erweiterung | 1.0.0 |
| Kompatibilität mit Contao Version | 2.10.x |
| Link zum Extension Repository | http://www.contao.org/erweiterungsliste/view/autocompleterTextfield.html |
| Link zum Tracker | http://contao-forge.org/projects/autocompleterTextfield/issues |
SVN: http://svn.4wardmedia.de/autocompleterTextfield
Inhaltsverzeichnis
AutocompleterTextfield
Autocompleting für ein Textfeld anhand von options, options_callback oder foreignKey. Über die Eval-Option storeId kann die ID bzw. der Array-Key anstatt der Textwert gespeichert werden.
Einfaches Textfeld, Vervollständigung anhand der tl_page, Speicherung der tl_page.id
'myPage' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_tmp']['myPage'], 'inputType' => 'autocompleterTextfield', 'foreignKey' => 'tl_page.title', 'eval' => array('storeId'=>true) ),
Einfaches Textfeld, Vervollständigung anhand von options
'myPage' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_tmp']['myPage'], 'inputType' => 'autocompleterTextfield', 'options' => array('Erster Eintrag','Zweiter Eintrag','Dritter Eintrag') ),
Verwendung im MultiColumnWizard
'einFeld' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_asd']['einFeld'], 'inputType' => 'multiColumnWizard', 'eval' => array( 'columnFields' => array ( 'myTxt' => array ( 'label' => array('label','desc'), 'inputType' => 'autocompleterTextfield', 'options' => array('Erster Eintrag','Zweiter Eintrag','Dritter Eintrag'), 'eval' => array('style'=>'width:180px') ), 'myTxt2' => array ( 'label' => array('label','desc'), 'inputType' => 'autocompleterTextfield', 'options_callback' => array('myClass','myCallback'), 'eval' => array('style'=>'width:180px') ), ) ), ),
Beispiel für einen options_callback
Falls die POST-Variable ("value") gesetzt ist, kann eine Vorselektierung stattfinden. Sie wird vom Autocompleter-Javascript übermittelt und enthält den eingegebenen String.
public function getProducts() { $this->import('Database'); // perhaps do some validation, cause POST-Vars are evil if($this->Input->post('value')) { $objProducts = $this->Database->prepare(' SELECT id,name FROM tl_product WHERE name LIKE ? ORDER BY name') ->execute('%'.$this->Input->post('value').'%'); } else { $objProducts = $this->Database->prepare(' SELECT id,name FROM tl_product ORDER BY name') ->execute(); } $prods = array(); while($objProducts->next()) $prods[$objProducts->id] = $objProducts->name; return $prods; }
