Select
TsgcHTMLComponent_Select — un menu a discesa select Bootstrap 5 con optgroup, selezione multipla, dimensionamento e binding ai dataset, in Delphi, C++ Builder e .NET.
TsgcHTMLComponent_Select — un menu a discesa select Bootstrap 5 con optgroup, selezione multipla, dimensionamento e binding ai dataset, in Delphi, C++ Builder e .NET.
Un menu a discesa che emette un form-select Bootstrap con etichetta. Aggiungi le opzioni (oppure collega un dataset), raggruppale facoltativamente e consenti la selezione multipla, quindi leggi la proprietà HTML.
TsgcHTMLComponent_Select
Bootstrap 5 form-select
Delphi, C++ Builder, .NET
Imposta Name, Label_ e un Placeholder, aggiungi le opzioni con AddOption (oppure AddOptionGroup), quindi leggi HTML (oppure inseriscilo in una pagina TsgcHTMLTemplate_Bootstrap).
uses
sgcHTML_Enums, sgcHTML_Component_Select;
var
oSelect: TsgcHTMLComponent_Select;
begin
oSelect := TsgcHTMLComponent_Select.Create(nil);
try
oSelect.Name := 'country';
oSelect.Label_ := 'Country';
oSelect.Placeholder := 'Select a country';
oSelect.Size := ssLarge;
oSelect.AddOption('es', 'Spain', True);
oSelect.AddOption('fr', 'France');
oSelect.AddOptionGroup('Americas', 'us', 'United States');
WebModule.Response := oSelect.HTML; // Bootstrap form-select
finally
oSelect.Free;
end;
end;
// Or fill it straight from a dataset:
oSelect.LoadFromDataSet(qryCountries, 'Code', 'Name', 'Region');
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Select.hpp
TsgcHTMLComponent_Select *oSelect = new TsgcHTMLComponent_Select(NULL);
try
{
oSelect->Name = "country";
oSelect->Label_ = "Country";
oSelect->Placeholder = "Select a country";
oSelect->Size = ssLarge;
oSelect->AddOption("es", "Spain", true);
oSelect->AddOption("fr", "France");
oSelect->AddOptionGroup("Americas", "us", "United States");
String html = oSelect->HTML; // Bootstrap form-select
}
__finally
{
delete oSelect;
}
using esegece.sgcWebSockets;
var select = new TsgcHTMLComponent_Select();
select.Name = "country";
select.Label_ = "Country";
select.Placeholder = "Select a country";
select.Size = TsgcHTMLSelectSize.ssLarge;
select.AddOption("es", "Spain", true);
select.AddOption("fr", "France");
select.AddOptionGroup("Americas", "us", "United States");
string html = select.HTML; // Bootstrap form-select
I membri che utilizzerai più spesso.
Options è una collezione di TsgcHTMLSelectOption (ciascuna con Value, Text, Selected, Disabled e Group); i metodi pratici AddOption(value, text, selected) e AddOptionGroup(group, value, text) la riempiono.
Name imposta il nome del campo, Label_ la didascalia, Placeholder un’opzione iniziale disabilitata e SelectID l’id dell’elemento (il valore predefinito è sel_<Name>).
Multiple lo trasforma in una lista a selezione multipla e VisibleItems imposta quante righe vengono mostrate contemporaneamente (l’attributo size).
Size è un TsgcHTMLSelectSize — ssDefault, ssSmall o ssLarge.
LoadFromDataSet(aDataSet, aValueField, aTextField, aGroupField) riempie le opzioni da una query, costruendo <optgroup> quando viene fornito un campo di gruppo; assegna DataSource per l’aggiornamento live.
Required e Disabled contrassegnano il controllo; HTML restituisce il <select> con etichetta con tutte le opzioni e gli optgroup.