AutoComplete

TsgcHTMLComponent_AutoComplete — renderuje pole tekstowe oparte na liście <datalist> HTML5 z sugestiami, bez potrzeby pisania JavaScript, w Delphi, C++ Builder i .NET.

TsgcHTMLComponent_AutoComplete

Komponent pola, który generuje element form-control Bootstrap powiązany z natywną listą <datalist>. Dodaj ciągi sugestii do Items, a następnie odczytaj właściwość HTML.

Klasa komponentu

TsgcHTMLComponent_AutoComplete

Renderuje

Pole Bootstrap + <datalist> HTML5

Języki

Delphi, C++ Builder, .NET

Utwórz go, dodaj sugestie, wyrenderuj

Ustaw Name i Label_, przekaż ciągi sugestii do Items, a następnie odczytaj HTML (albo umieść go na stronie TsgcHTMLTemplate_Bootstrap).

uses
  sgcHTML_Component_AutoComplete;

var
  oAuto: TsgcHTMLComponent_AutoComplete;
begin
  oAuto := TsgcHTMLComponent_AutoComplete.Create(nil);
  try
    oAuto.Name := 'country';
    oAuto.Label_ := 'Country';
    oAuto.Placeholder := 'Start typing...';
    oAuto.MinLength := 2;

    oAuto.Items.Add('Spain');
    oAuto.Items.Add('France');
    oAuto.Items.Add('Germany');

    WebModule.Response := oAuto.HTML;   // <input> + <datalist>
  finally
    oAuto.Free;
  end;
end;
// includes: sgcHTML_Component_AutoComplete.hpp

TsgcHTMLComponent_AutoComplete *oAuto = new TsgcHTMLComponent_AutoComplete(NULL);
try
{
  oAuto->Name = "country";
  oAuto->Label_ = "Country";
  oAuto->Placeholder = "Start typing...";
  oAuto->MinLength = 2;

  oAuto->Items->Add("Spain");
  oAuto->Items->Add("France");
  oAuto->Items->Add("Germany");

  String html = oAuto->HTML;   // <input> + <datalist>
}
__finally
{
  delete oAuto;
}
using esegece.sgcWebSockets;

var auto = new TsgcHTMLComponent_AutoComplete();
auto.Name = "country";
auto.Label_ = "Country";
auto.Placeholder = "Start typing...";
auto.MinLength = 2;

auto.Items.Add("Spain");
auto.Items.Add("France");
auto.Items.Add("Germany");

string html = auto.HTML;   // <input> + <datalist>

Kluczowe właściwości i metody

Składniki, po które sięgasz najczęściej.

Pole

Name ustawia atrybut name pola; Label_ renderuje nad nim form-label; Value wstępnie wypełnia pole.

Sugestie

Items (TStringList) przechowuje ciągi sugestii, które stają się pozycjami <option> wewnątrz <datalist>.

Zachowanie

Placeholder wyświetla tekst podpowiedzi; MinLength ustawia, ile znaków trzeba wpisać, zanim pojawią się sugestie (domyślnie 1).

Tożsamość

AutoCompleteID ustawia atrybut id elementu współdzielony przez pole i powiązaną listę <datalist>; domyślnie sgcAutoComplete.

Wynik

HTML zwraca kontener mb-3 zawierający etykietę, pole form-control i wypełnioną listę <datalist>.

Układ

Dziedziczone Section, ColumnWidth i RowGroup umieszczają pole na siatce TsgcHTMLPageBuilder.

Poznawaj dalej

Wszystkie komponenty sgcHTMLPrzejrzyj pełną matrycę funkcji 60+ komponentów.
Pobierz bezpłatną wersję próbną30-dniowa wersja próbna zawiera projekty demonstracyjne 60.HTML.
CennikLicencje Single, Team i Site z pełnym kodem źródłowym.

Gotowy, aby zacząć?

Pobierz bezpłatną wersję próbną i dodaj pola autouzupełniania do swojej aplikacji webowej w Delphi, C++ Builder lub .NET.