AutocompleterTextfield

Aus Contao Community Documentation


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

AutocompleterTextfield

AutocompleterTextfield.png

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;
}
Ansichten
Meine Werkzeuge

Contao Community Documentation

... aber beim nächsten Mal nehm ich einfach den Catalog... da hab ich weniger Arbeit mit.

MacKP
Navigation
Verstehen
Verwenden
Entwickeln
Verschiedenes
Werkzeuge