* Checked and IsDisabled

This commit is contained in:
Michaël Van Canneyt 2023-08-05 20:39:51 +02:00
parent a89aeae608
commit 34e96dd494
2 changed files with 100 additions and 0 deletions

View File

@ -43,10 +43,14 @@ Type
FStopPropagation: Boolean; FStopPropagation: Boolean;
FBeforeBind : TNotifyEvent; FBeforeBind : TNotifyEvent;
FAfterBind : TNotifyEvent; FAfterBind : TNotifyEvent;
function GetChecked: Boolean;
function GetDisabled: Boolean;
function GetIndex: Integer; function GetIndex: Integer;
procedure SetActionList(AValue: THTMLCustomElementActionList); procedure SetActionList(AValue: THTMLCustomElementActionList);
procedure SetChecked(AValue: Boolean);
procedure SetCSSSelector(AValue: String); procedure SetCSSSelector(AValue: String);
procedure SetCustomEvents(AValue: String); procedure SetCustomEvents(AValue: String);
procedure SetDisabled(AValue: Boolean);
procedure SetElementID(AValue: String); procedure SetElementID(AValue: String);
procedure SetIndex(AValue: Integer); procedure SetIndex(AValue: Integer);
Protected Protected
@ -61,8 +65,12 @@ Type
Public Public
Destructor Destroy; override; Destructor Destroy; override;
Class Function GetElementChecked(aElement : TJSHTMLElement) : boolean; virtual;
Class Function GetElementDisabled(aElement : TJSHTMLElement) : boolean; virtual;
Class Function GetElementValue(aElement : TJSHTMLElement) : String; virtual; Class Function GetElementValue(aElement : TJSHTMLElement) : String; virtual;
Class Procedure SetElementValue(aElement : TJSHTMLElement; const aValue : String; asHTML : Boolean = false); virtual; Class Procedure SetElementValue(aElement : TJSHTMLElement; const aValue : String; asHTML : Boolean = false); virtual;
Class Procedure SetElementChecked(aElement : TJSHTMLElement; const aValue : Boolean); virtual;
Class Procedure SetElementDisabled(aElement : TJSHTMLElement; const aValue : Boolean); virtual;
function GetParentComponent: TComponent; override; function GetParentComponent: TComponent; override;
function HasParent: Boolean; override; function HasParent: Boolean; override;
Procedure Bind; Procedure Bind;
@ -82,6 +90,8 @@ Type
// When reading, only the first value is returned in case of multiple elements. // When reading, only the first value is returned in case of multiple elements.
// When writing, the value is set on all elements. // When writing, the value is set on all elements.
Property Value : String Read GetValue Write SetValue; Property Value : String Read GetValue Write SetValue;
property checked : Boolean Read GetChecked write SetChecked;
property Disabled : Boolean Read GetDisabled Write SetDisabled;
Public Public
// These can be published in descendents // These can be published in descendents
Property Events : THTMLEvents Read FEvents Write FEvents; Property Events : THTMLEvents Read FEvents Write FEvents;
@ -380,6 +390,17 @@ begin
FActionList.AddAction(Self); FActionList.AddAction(Self);
end; end;
procedure THTMLCustomElementAction.SetChecked(AValue: Boolean);
procedure DoSetChecked(aElement: TJSHTMLElement);
begin
SetElementChecked(aElement,aValue);
end;
begin
ForEach(@DoSetChecked);
end;
function THTMLCustomElementAction.GetIndex: Integer; function THTMLCustomElementAction.GetIndex: Integer;
begin begin
if Assigned(FActionList) then if Assigned(FActionList) then
@ -388,6 +409,18 @@ begin
Result:=-1; Result:=-1;
end; end;
function THTMLCustomElementAction.GetChecked: Boolean;
begin
if (Length(FElements)>0) and Assigned (FElements[0]) then
Result:=GetElementChecked(FElements[0]);
end;
function THTMLCustomElementAction.GetDisabled: Boolean;
begin
if (Length(FElements)>0) and Assigned (FElements[0]) then
Result:=GetElementDisabled(FElements[0]);
end;
function THTMLCustomElementAction.GetValue: String; function THTMLCustomElementAction.GetValue: String;
begin begin
if (Length(FElements)>0) and Assigned (FElements[0]) then if (Length(FElements)>0) and Assigned (FElements[0]) then
@ -425,6 +458,18 @@ begin
Inherited; Inherited;
end; end;
class function THTMLCustomElementAction.GetElementChecked(
aElement: TJSHTMLElement): boolean;
begin
Result:=aElement.IsChecked;
end;
class function THTMLCustomElementAction.GetElementDisabled(
aElement: TJSHTMLElement): boolean;
begin
Result:=aElement.IsDisabled;
end;
class function THTMLCustomElementAction.GetElementValue(aElement: TJSHTMLElement class function THTMLCustomElementAction.GetElementValue(aElement: TJSHTMLElement
): String; ): String;
begin begin
@ -455,6 +500,18 @@ begin
aElement.InputValue:=aValue; aElement.InputValue:=aValue;
end; end;
class procedure THTMLCustomElementAction.SetElementChecked(
aElement: TJSHTMLElement; const aValue: Boolean);
begin
aElement.IsChecked:=aValue;
end;
class procedure THTMLCustomElementAction.SetElementDisabled(
aElement: TJSHTMLElement; const aValue: Boolean);
begin
aElement.IsDisabled:=aValue;
end;
procedure THTMLCustomElementAction.SetCSSSelector(AValue: String); procedure THTMLCustomElementAction.SetCSSSelector(AValue: String);
begin begin
if (FCSSSelector=aValue) then exit; if (FCSSSelector=aValue) then exit;
@ -471,6 +528,16 @@ begin
BindElementEvents; BindElementEvents;
end; end;
procedure THTMLCustomElementAction.SetDisabled(AValue: Boolean);
procedure DoSetChecked(aElement: TJSHTMLElement);
begin
SetElementDisabled(aElement,aValue);
end;
begin
ForEach(@DoSetChecked);
end;
procedure THTMLCustomElementAction.SetElementID(AValue: String); procedure THTMLCustomElementAction.SetElementID(AValue: String);
begin begin
if (FElementID=aValue) then exit; if (FElementID=aValue) then exit;

View File

@ -83,8 +83,12 @@ Type
private private
Function GetData(aName: String): String; Function GetData(aName: String): String;
function GetInputValue: String; function GetInputValue: String;
function GetIsChecked: Boolean;
function GetIsDisabled: Boolean;
procedure SetData(Index: String; AValue: String); procedure SetData(Index: String; AValue: String);
procedure SetInputValue(const aValue: String); procedure SetInputValue(const aValue: String);
procedure SetIsChecked(AValue: Boolean);
procedure SetIsDisabled(AValue: Boolean);
Public Public
Function ParentHTMLElement : TJSHTMLElement; Function ParentHTMLElement : TJSHTMLElement;
Function FindParent(aMatch : TJSHTMLElementMatcher) : TJSHTMLElement; Function FindParent(aMatch : TJSHTMLElementMatcher) : TJSHTMLElement;
@ -95,6 +99,8 @@ Type
procedure AddRemoveClass(Const aAddClass, aRemoveClass: String); overload; procedure AddRemoveClass(Const aAddClass, aRemoveClass: String); overload;
function HasClass(const aClass: String): Boolean; function HasClass(const aClass: String): Boolean;
Property InputValue: String Read GetInputValue Write SetInputValue; Property InputValue: String Read GetInputValue Write SetInputValue;
Property IsChecked : Boolean Read GetIsChecked Write SetIsChecked;
Property IsDisabled: Boolean Read GetIsDisabled Write SetIsDisabled;
Property Data[Index: String]: String Read GetData Write SetData; Property Data[Index: String]: String Read GetData Write SetData;
end; end;
@ -376,6 +382,19 @@ begin
Result:=GetElementValue(Self) Result:=GetElementValue(Self)
end; end;
function TJSHTMLElementHelper.GetIsChecked: Boolean;
begin
if Self is TJSHTMLInputElement then
Result:=TJSHTMLInputElement(Self).Checked
else
Result:=False;
end;
function TJSHTMLElementHelper.GetIsDisabled: Boolean;
begin
Result:=Assigned(Self) and (hasOwnProperty('disabled'))
end;
procedure TJSHTMLElementHelper.SetData(Index: String; AValue: String); procedure TJSHTMLElementHelper.SetData(Index: String; AValue: String);
begin begin
Dataset.Map[Index]:=aValue; Dataset.Map[Index]:=aValue;
@ -400,6 +419,20 @@ begin
SetElementValue(Self,aValue) SetElementValue(Self,aValue)
end; end;
procedure TJSHTMLElementHelper.SetIsChecked(AValue: Boolean);
begin
if (Self is TJSHTMLInputElement) then
TJSHTMLInputElement(Self).Checked:=aValue;
end;
procedure TJSHTMLElementHelper.SetIsDisabled(AValue: Boolean);
begin
if aValue then
Self.Properties['disabled']:=True
else
Self.Properties['disabled']:=Undefined;
end;
function TJSHTMLElementHelper.ParentHTMLElement: TJSHTMLElement; function TJSHTMLElementHelper.ParentHTMLElement: TJSHTMLElement;
Var Var