AutoComplete Component — sgcHTML | eSeGeCe

AutoComplete

TsgcHTMLComponent_AutoComplete — render a text input backed by an HTML5 <datalist> of suggestions, with no JavaScript required, in Delphi, C++ Builder and .NET.

TsgcHTMLComponent_AutoComplete

An input component that emits a Bootstrap form-control wired to a native <datalist>. Add the suggestion strings to Items, then read the HTML property.

Component class

TsgcHTMLComponent_AutoComplete

Renders

Bootstrap input + HTML5 <datalist>

Languages

Delphi, C++ Builder, .NET

Create it, add suggestions, render it

Set Name and Label_, push suggestion strings into Items, then read HTML (or drop it into a TsgcHTMLTemplate_Bootstrap page).

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>

Key properties & methods

The members you reach for most often.

Field

Name sets the input's name; Label_ renders a form-label above it; Value pre-fills the field.

Suggestions

Items (a TStringList) holds the suggestion strings that become <option> entries inside the <datalist>.

Behavior

Placeholder shows hint text; MinLength sets how many characters are typed before suggestions appear (defaults to 1).

Identity

AutoCompleteID sets the element id shared by the input and its linked <datalist>; it defaults to sgcAutoComplete.

Output

HTML returns the mb-3 wrapper containing the label, the form-control input and the populated <datalist>.

Layout

Inherited Section, ColumnWidth and RowGroup place the field on a TsgcHTMLPageBuilder grid.

Keep exploring

Online HelpFull API reference and usage guide for this component.
All sgcHTML ComponentsBrowse the full feature matrix of 80+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and add autocomplete inputs to your Delphi, C++ Builder or .NET web app.