|
Datei: /pages/tutorials/textbox/textbox-09.php
<?php class Textbox09 extends Page { public function InitializeComponent() { parent::$PAGE_TITLE = "Tutorial : TextBox search with autocomplete and dynamic filter"; $form = new Form($this); // Create ComboBox object (filter) // List of actif and inactif is available on: // http://www.website-php.com/en/tutorials/database/database-05.html // You can modify the list of inactif on: // http://www.website-php.com/en/tutorials/database/database-07.html $filter = new ComboBox($form); $filter->addItem(1, "ACTIF"); $filter->addItem(0, "INACTIF"); // Create TextBox object $search_text = new TextBox($form); // Create AutoCompleteEvent object $autocompete_event = new AutoCompleteEvent($form); $autocompete_event->onSelect("onSelectAutoComplete"); $autocompete_event->setAjaxEvent(); $autocompete_event->disableAjaxWaitMessage(); // Create AutoComplete object (with filter in the URL) $autocomplete = new AutoComplete( new Url("xml/textbox-search.json?". "filter='+$('#".$filter->getId()."').val()+'"), 1, $autocompete_event);
// Refresh URL when change filter $filter->onChangeJS("$('#".$search_text->getId()."').autocomplete(". "'option', 'source', '".$this->getBaseLanguageURL(). "xml/textbox-search.json?". "filter='+$('#".$filter->getId()."').val());"); // Set autocomplete on the TextBox $search_text->setAutoComplete($autocomplete); $form->setContent(new WSPObject($filter, $search_text)); $this->render = $form; } public function onSelectAutoComplete($sender, $id) { $this->addObject( new DialogBox("onSelectAutoComplete", "URL: ".$id) ); } } ?>
Zurück zum Tutorial der Komponente Textbox
|
TextboxSearch: Datei: /pages/xml/textbox-search.php
<?php class TextboxSearch extends Page { public function InitializeComponent() { $this->render = new AutoCompleteResult(); $_GET['term'] = trim(utf8decode(strip_tags($_GET['term']))); $_GET['term'] = addslashes($_GET['term']); $sql = new SqlDataView(new FavoritePageDbTable()); if (isset($_GET['filter']) && ($_GET['filter']==1 || $_GET['filter']==0)) { // When there is a filter param used $_GET['filter'] = trim(utf8decode(strip_tags($_GET['filter']))); $_GET['filter'] = addslashes($_GET['filter']); if ($_GET['filter'] == 0) { $_GET['filter'] = " IS NULL"; } else { $_GET['filter'] = " = 1"; } $sql->setClause(FavoritePageDbTable::FIELD_NAME. " LIKE '%".$_GET['term']."%' AND ". FavoritePageDbTable::FIELD_ACTIF. $_GET['filter']); } else { // Without filter $sql->setClause(FavoritePageDbTable::FIELD_NAME. " LIKE '%".$_GET['term']."%'"); } $ind = 0; $it = $sql->retrieve(); while ($it->hasNext()) { $row = $it->next(); $this->render->add( $row->getValue(FavoritePageDbTable::FIELD_URL), $row->getValue(FavoritePageDbTable::FIELD_NAME), $row->getValue(FavoritePageDbTable::FIELD_NAME)); $ind++; } if ($ind == 0) { $this->render->add("", utf8_encode("No result"), ""); } } } ?>
|
|
|
|
|