AutocompleterTextfield: Unterschied zwischen den Versionen
Aus Contao Community Documentation
Psi (Diskussion | Beiträge) |
Psi (Diskussion | Beiträge) |
||
| (3 dazwischenliegende Versionen von einem Benutzer werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
| + | [[Category:Dev_HOWTOS]] | ||
| + | [[Category:Development]] | ||
[[Category:Extensions]] | [[Category:Extensions]] | ||
{{ExtInfo | {{ExtInfo | ||
| Zeile 8: | Zeile 10: | ||
| SVN=http://svn.4wardmedia.de/autocompleterTextfield | | SVN=http://svn.4wardmedia.de/autocompleterTextfield | ||
}} | }} | ||
| + | '''Github''': https://github.com/psi-4ward/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. | ||
| − | |||
==Einfaches Textfeld, Vervollständigung anhand der tl_page, Speicherung der tl_page.id== | ==Einfaches Textfeld, Vervollständigung anhand der tl_page, Speicherung der tl_page.id== | ||
| − | |||
<source lang="php"> | <source lang="php"> | ||
'myPage' => array | 'myPage' => array | ||
| Zeile 29: | Zeile 32: | ||
==Einfaches Textfeld, Vervollständigung anhand von ''options''== | ==Einfaches Textfeld, Vervollständigung anhand von ''options''== | ||
| − | |||
<source lang="php"> | <source lang="php"> | ||
'myPage' => array | 'myPage' => array | ||
| Zeile 41: | Zeile 43: | ||
==Verwendung im [[MultiColumnWizard]]== | ==Verwendung im [[MultiColumnWizard]]== | ||
| − | |||
<source lang="php"> | <source lang="php"> | ||
'einFeld' => array | 'einFeld' => array | ||
| Zeile 67: | 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> | ||
Aktuelle Version vom 13. Juni 2013, 16:39 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 |
Github: https://github.com/psi-4ward/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; }
