SuggestInput
Našeptávač pro textové pole.
| Verze | 1.1 |
|---|---|
| Download | http://github.com/…estInput.zip |
| Demo | http://mars.halousek.eu/suggester-test |
| Demo download | http://github.com/…estInput.zip |
| Git | git://github.com/peci1/Nette-SuggestInput.git |
| Git (webové rozhraní) | http://github.com/…SuggestInput |
| Forum thread | http://forum.nette.org/…b-naseptavac |
| Autor | Martin Pecka |
Ahoj, z dlouhé chvíle jsem si napsal našeptávač :)
Malá ochutnávka, jak se používá:
SuggesterTestPresenter.php
protected function createComponentTestForm()
{
$form = new AppForm();
//see further functions' definitions for suggester factories and
//action definitions
//the simplest case - suggesting from an array
$form->addSuggestInput('suggest1', "Simple ArraySuggester")
//here is the link to the action that provides suggestions
->setSuggestLink($this->link('suggestAhoj'));
//you can also use this as a simple input with a non-changing tooltip
//which is displayed while the input is active
$form->addSuggestInput('suggest2', "Using ConstantSuggester as tooltip")
->setSuggestLink($this->link('suggestConstant'))
//and this way you set some JS options (defined in jquery.suggest.js)
->addJsOptions('itemsPerPage', 10)
->addJsOptions('noControl', true)
->addJsOptions('minchars', 0)
->addJsOptions('constant', true);
//checking if the submitted value is one of the suggested ones
$form->addSuggestInput('suggest3', "Suggested values check on form send")
->setSuggestLink($this->link('suggestAhoj'))
//here is the suggester that is used, only required if you want to use the following validator
->setSuggester($this['ahojSuggester'])
//this validation rule checks if the entered value is one of the suggested items
//the FALSE at the end means we do not allow empty value as a value
->addRule(SuggestInput::SUGGESTED_ONLY, 'Vybraná možnost musí být jedna z nabízených', FALSE);
//dibi suggester - suggest from a database table
$form->addSuggestInput('suggest4', "DibiSuggester")
->setSuggestLink($this->link('suggestDibi'));
$form->addSuggestInput('suggest5', 'Retrieving data through a signal')
->setSuggestLink($this->link('signalSuggest!'))
->addJsOptions('itemsPerPage', 10)
->addJsOptions('noControl', true)
->addJsOptions('minchars', 0)
->addJsOptions('constant', true)
->addJsOptions('componentName', $this->getName()); //important when using signals
$form->addSubmit('sub', 'Submit');
return $form;
}
public function actionSuggestAhoj($typedText = '')
{
$this->matches = $this['ahojSuggester']->getSuggestions($typedText);
}
public function renderSuggestAhoj()
{
$this->terminate(new JsonResponse($this->matches));
}
public function actionSuggestConstant($typedText = '')
{
$this->matches = $this['constantSuggester']->getSuggestions(NULL);
}
public function renderSuggestConstant()
{
$this->terminate(new JsonResponse($this->matches));
}
public function actionSuggestDibi($typedText = '')
{
$this->matches = $this['dibiSuggester']->getSuggestions($typedText);
}
public function renderSuggestDibi()
{
$this->terminate(new JsonResponse($this->matches));
}
public function handleSignalSuggest($typedText = '')
{
$this->matches = $this['constantSuggester']->getSuggestions(NULL);
$this->terminate(new JsonResponse($this->matches));
}
protected function createComponentAhojSuggester()
{
$suggester = new ArraySuggester();
$data = array(
'ahoj', 'ahojk', 'ahojky', 'bah', 'bahn', 'bahno',
'cíl', 'cíle', 'cílev', 'cílevě', 'cílevěd', 'cílevědo',
'cílevědom', 'cílevědomý', 'ěščřžýáíéúůďťň', 'ĚŠČŘŽÝÁÍÉÚŮĎŤŇ',
'ahoj ahoj', 'hola hou'
);
$suggester
->setItems($data)
//setting this will match only items beginning with query string
//->matchFromBeginning(TRUE)
;
return $suggester;
}
protected function createComponentConstantSuggester()
{
$suggester = new ConstantSuggester();
$data = array('A great tooltip', 'Is on more lines!', 'Type "Expedice Mars 2009" in the last input!');
return $suggester->setItems($data);
}
/* COOL!!! */
protected function createComponentDibiSuggester()
{
$suggester = new DibiSuggester();
return $suggester
->setTable('suggestions')
->setColumn('text')
->setWhere('[text] LIKE %s');
}
Víc dokumentace je v kódu a v balíku.
Tak si ho užijte!
