Ver código fonte

* Allow to create fixed element

Michaël Van Canneyt 1 ano atrás
pai
commit
0ea98f71a0

+ 24 - 0
packages/webwidget/src/dbhtmlwidgets.pp

@@ -138,6 +138,8 @@ Type
   
   TCustomDBSelectWidget = class(TCustomSelectWidget)
   Private
+    FClearValue: String;
+    FClearValueText: String;
     FItemTemplate: String;
     FLink : TSelectLink;
     FItemField: String;
@@ -173,6 +175,7 @@ Type
     Function CreateOptionEnumerator: TSelectOptionEnumerator; override;
     procedure ActiveChanged; virtual;
     Procedure DoUnRender(aParent : TJSHTMLElement) ; override;
+    function CreateFixedElements(aSelect: TJSHTMLSelectElement): Integer; override;
   Protected
     // properties that can be published in descendents
     Property Datasource : TDatasource Read GetDatasource write SetDatasource;
@@ -181,6 +184,8 @@ Type
     Property ItemTemplate: String Read FItemTemplate Write SetItemTemplate;
     Property NullIsNotValue : Boolean Read FNullIsNotValue Write SetNullIsNotValue;
     Property Value : String Read GetValue Write SetValue;
+    Property ClearValue : String Read FClearValue Write FClearValue;
+    Property ClearValueText : String Read FClearValueText  Write FClearValueText;
   Public
     constructor Create(aOwner : TComponent); override;
     destructor destroy; override;
@@ -207,6 +212,9 @@ Type
     Property NullIsNotValue;
     property SelectedIndex;
     Property Multiple;
+    Property ClearValue;
+    Property ClearValueText;
+    Property Size;
   end;
 
 
@@ -377,6 +385,22 @@ begin
   inherited DoUnRender(aParent);
 end;
 
+function TCustomDBSelectWidget.CreateFixedElements(aSelect: TJSHTMLSelectElement): Integer;
+var
+  O : TJSHTMLOptionElement;
+
+begin
+  Result:=0;
+  if ClearValueText<>'' then
+    begin
+    O:=TJSHTMLOptionElement(Document.createElement('OPTION'));
+    O.innerText:=ClearValueText;
+    O.value:=ClearValue;
+    aSelect.appendChild(O);
+    Result:=1;
+    end;
+end;
+
 constructor TCustomDBSelectWidget.Create(aOwner: TComponent);
 begin
   inherited Create(aOwner);

+ 11 - 3
packages/webwidget/src/htmlwidgets.pp

@@ -483,6 +483,7 @@ Type
         Property Select: TCustomSelectWidget Read FSelect;
       end;
   Protected
+    function CreateFixedElements(aSelect: TJSHTMLSelectElement): Integer; virtual;
     function GetItemCount: Integer; virtual;
     Function CreateOptionEnumerator : TSelectOptionEnumerator; virtual; abstract;
     Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
@@ -2177,6 +2178,13 @@ begin
     SelectElement.Size:=FSize;
 end;
 
+Function TCustomSelectWidget.CreateFixedElements(aSelect: TJSHTMLSelectElement) : Integer;
+
+begin
+  if aSelect<>Nil then ;
+  Result:=0;
+end;
+
 procedure TCustomSelectWidget.BuildOptions(aSelect: TJSHTMLSelectElement);
 
 Var
@@ -2189,7 +2197,7 @@ begin
   SetLength(FOptions,0);
   aSelect.InnerHTML:='';
   // Rebuild
-  Idx:=0;
+  Idx:=CreateFixedElements(aSelect);
   enum:=CreateOptionEnumerator;
   While enum.MoveNext do
     begin
@@ -2226,8 +2234,8 @@ Var
 begin
   inherited ApplyWidgetSettings(aElement);
   el.multiple:=Self.Multiple;
-    if Size<>-1 then
-  el.Size:=Self.Size;
+  if Size<>-1 then
+    el.Size:=Self.Size;
   BuildOptions(el);
   // We need to force this.
   if SelectedIndex=-1 then