-
Notifications
You must be signed in to change notification settings - Fork 10
/
dw.vcl.FluidForm.pas
115 lines (93 loc) · 3.21 KB
/
dw.vcl.FluidForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
unit dw.vcl.FluidForm;
interface
uses
System.Classes, dw.vcl.InputForm, DWTypes, DWElementTag;
type
TDWFormEncType = (iwbsfeDefault, iwbsfeMultipart, iwbsfeText);
TDWFluidForm = class(TDWCustomInputForm)
private
FEncType: TDWFormEncType;
FOnSubmit: TDWInputFormSubmitEvent;
procedure DoSubmit(aParams: TStrings);
protected
procedure InternalRenderCss(var ACss: string); override;
procedure InternalRenderScript(const AHTMLName: string; AScript: TStringList); override;
function RenderHTML: TDWElementTag; override;
function RenderAsync: TDWElementXHTMLTag; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetRoleString: string; override;
published
property EncType: TDWFormEncType read FEncType write FEncType default iwbsfeDefault;
property OnSubmit: TDWInputFormSubmitEvent read FOnSubmit write FOnSubmit;
end;
implementation
uses
System.SysUtils, dw.vcl.Common, DWUtils;
{ TIWBSFluidForm }
constructor TDWFluidForm.Create(AOwner: TComponent);
begin
inherited;
FEncType := iwbsfeDefault;
end;
destructor TDWFluidForm.Destroy;
begin
inherited;
end;
procedure TDWFluidForm.DoSubmit(aParams: TStrings);
begin
if Assigned(FOnSubmit) then
FOnSubmit(aParams);
{ TODO 1 -oDELCIO -cIMPLEMENT : Need to implement TIWBSFluidForm Submit event }
// aReply.SendRedirect(aApplication.SessionInternalUrlBase);
end;
function TDWFluidForm.GetRoleString: string;
begin
Result := 'form';
end;
procedure TDWFluidForm.InternalRenderCss(var ACss: string);
begin
TDWBSCommon.AddCssClass(ACss, 'iwbs-form-fluid');
end;
procedure TDWFluidForm.InternalRenderScript(const AHTMLName: string; AScript: TStringList);
begin
inherited;
if ValidationEnabled and Hasvalidator then
AScript.Add('$("#' + HTMLName + '").validator(''validate'');');
end;
function TDWFluidForm.RenderAsync: TDWElementXHTMLTag;
begin
Result := inherited;
if ValidationEnabled and Hasvalidator then
DWApplication.CallBackResp.AddScriptToExecute
('$("#' + HTMLName + '").validator(''validate'');', False);
end;
function TDWFluidForm.RenderHTML: TDWElementTag;
var
LParentForm: TDWCustomInputForm;
begin
LParentForm := DWFindParentInputForm(Parent);
if LParentForm <> nil then
raise Exception.Create('forms can not be nested, you try to put ' + Name + ' inside ' +
LParentForm.Name);
Result := inherited;
if ValidationEnabled and Hasvalidator then
Result.AddStringParam('data-toggle', 'validator');
if Assigned(FOnSubmit) then
begin
raise Exception.Create
('TIWBSFluidForm Submit event not implemented yet. Contribute with this.');
{ TODO 1 -oDELCIO -cIMPLEMENT : Need to implement TIWBSFluidForm Submit event }
(* Result.AddStringParam('method', 'post');
if FEncType = iwbsfeMultipart then
Result.AddStringParam('enctype', 'multipart/form-data')
else if FEncType = iwbsfeText then
Result.AddStringParam('enctype', 'text/plain');
Result.AddStringParam('action', DWApplication.RegisterCallBack( HTMLName+'.FormSubmit', DoSubmit, (FEncType = iwbsfeMultipart)));
*)
end
else
Result.AddStringParam('onSubmit', 'return FormDefaultSubmit();');
end;
end.