PHP code example of vojtys / typeahead
1. Go to this page and download the library: Download vojtys/typeahead library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vojtys / typeahead example snippets
public function createComponentTypeaheadForm(): Form
{
$form = new Form();
/** @var TypeaheadInput $typeahead */
// name, label, display (input displayed value), suggestion callback
$typeahead = $form->addTypeahead('typeahead', 'Typeahead', 'title', function($display, $q) {
return $this->searchBy($q); // returns array result [title => 'foo', description => 'foo foo']
});
$typeahead->setPlaceholder('Začni psát...'); // initial placeholder
// add handlebars templates (http://handlebarsjs.com/)
// suggestion template
$typeahead->setSuggestionTemplate(function(Html $template) {
$inner = Html::el('div')->setText('{{title}} – {{description}}');
return $template->addHtml($inner);
});
// empty template
$typeahead->setNotFoundTemplate(function(Html $template) {
$inner = Html::el('div')->setText('nic tu neni');
return $template->addHtml($inner);
});
$form->addSubmit('ok', 'Odeslat');
return $form;
}
yaml
extensions:
typehead: Vojtys\Forms\Typeahead\TypeaheadExtension
typeahead:
limit: 10
minLength: 2
highlight: true