Browse Source

* Add placeholder

Michaël Van Canneyt 1 year ago
parent
commit
7d37ef3f4e
1 changed files with 26 additions and 1 deletions
  1. 26 1
      packages/webwidget/src/htmlwidgets.pp

+ 26 - 1
packages/webwidget/src/htmlwidgets.pp

@@ -207,6 +207,7 @@ Type
   private
   private
     FMaxLength : Integer;
     FMaxLength : Integer;
     FMinLength : Integer;
     FMinLength : Integer;
+    FPlaceHolder : String;
     FTextType : TInputTextType;
     FTextType : TInputTextType;
     function GetAsNumber: NativeInt;
     function GetAsNumber: NativeInt;
     function GetMaxLength: NativeInt;
     function GetMaxLength: NativeInt;
@@ -216,6 +217,7 @@ Type
     procedure SetMaxLength(AValue: NativeInt);
     procedure SetMaxLength(AValue: NativeInt);
     procedure SetMinLength(AValue: NativeInt);
     procedure SetMinLength(AValue: NativeInt);
     procedure SetTextType(AValue: TInputTextType);
     procedure SetTextType(AValue: TInputTextType);
+    procedure SetPlaceHolder(AValue: String);
   Protected
   Protected
     Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
     Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
   Public
   Public
@@ -225,6 +227,7 @@ Type
     Property Value;
     Property Value;
     Property ValueName;
     Property ValueName;
     Property Required;
     Property Required;
+    Property PlaceHolder : String Read FPlaceHolder Write SetPlaceHolder;
     Property TextType : TInputTextType Read GetTextType Write SetTextType;
     Property TextType : TInputTextType Read GetTextType Write SetTextType;
     property AsNumber : NativeInt Read GetAsNumber Write SetAsNumber;
     property AsNumber : NativeInt Read GetAsNumber Write SetAsNumber;
     Property MaxLength : NativeInt Read GetMaxLength Write SetMaxLength;
     Property MaxLength : NativeInt Read GetMaxLength Write SetMaxLength;
@@ -369,6 +372,7 @@ Type
     FLines: TStrings;
     FLines: TStrings;
     FIgnoreChanges : Boolean;
     FIgnoreChanges : Boolean;
     FMaxLength: Cardinal;
     FMaxLength: Cardinal;
+    FPlaceHolder,
     FValueName : String;
     FValueName : String;
     FRows,
     FRows,
     FColumns : Cardinal;
     FColumns : Cardinal;
@@ -392,6 +396,7 @@ Type
     procedure SetRows(AValue: Cardinal);
     procedure SetRows(AValue: Cardinal);
     procedure SetText(AValue: String);
     procedure SetText(AValue: String);
     procedure SetValueName(AValue: string);
     procedure SetValueName(AValue: string);
+    procedure SetPlaceHolder(AValue: string);
     Function GetTextArea : TJSHTMLTextAreaElement;
     Function GetTextArea : TJSHTMLTextAreaElement;
     procedure SetWrap(AValue: TTextAreaWrap);
     procedure SetWrap(AValue: TTextAreaWrap);
   Protected
   Protected
@@ -407,7 +412,8 @@ Type
     Function HTMLTag : String; override;
     Function HTMLTag : String; override;
     Property InnerHTML : String Read GetText Write SetText;
     Property InnerHTML : String Read GetText Write SetText;
   Published
   Published
-    Property ValueName : string Read GetValueName Write SetValueName;
+    Property ValueName : string Read FPlaceHolder Write SetPlaceHolder;
+    Property Placeholder : string Read GetValueName Write SetValueName;
     Property Rows : Cardinal Read GetRows Write SetRows;
     Property Rows : Cardinal Read GetRows Write SetRows;
     Property Columns : Cardinal Read GetColumns Write SetColumns;
     Property Columns : Cardinal Read GetColumns Write SetColumns;
     Property Lines : TStrings Read GetLines Write SetLines;
     Property Lines : TStrings Read GetLines Write SetLines;
@@ -2504,6 +2510,14 @@ begin
     TextArea.Name:=aValue;
     TextArea.Name:=aValue;
 end;
 end;
 
 
+procedure TTextAreaWidget.SetPlaceHolder(AValue: string);
+begin
+  if aValue=FPlaceHolder then exit;
+  FPlaceHolder:=aValue;
+  if IsRendered then
+    TextArea.PlaceHolder:=aValue;
+end;
+
 procedure TTextAreaWidget.SetName(const NewName: TComponentName);
 procedure TTextAreaWidget.SetName(const NewName: TComponentName);
 
 
 var
 var
@@ -3180,6 +3194,17 @@ begin
     Inp.name:=aValue;
     Inp.name:=aValue;
 end;
 end;
 
 
+procedure TTextInputWidget.SetPlaceHolder(AValue: String);
+Var
+  Inp : TJSHTMLInputElement;
+begin
+  if aValue=PlaceHolder then exit;
+  FPlaceHolder:=aValue;
+  Inp:=InputElement;
+  If Assigned(Inp) then
+    Inp.placeHolder:=aValue;
+end;
+
 procedure TCustomInputWidget.SetName(const NewName: TComponentName);
 procedure TCustomInputWidget.SetName(const NewName: TComponentName);
 
 
 Var
 Var