Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
Pushed to 3 repositories · View In Graph Contained in tip and canonical

Created NumberControl.

Changeset 7df8b0f50c6c

Parent 1b730dac7e83

by Profile picture of William GrossWilliam Gross

Changes to 10 files · Browse files at 7df8b0f50c6c Showing diff from parent 1b730dac7e83 Diff from another changeset...

Change 1 of 1 Show Entire File Core/​Core.csproj Stacked
 
406
407
408
 
 
409
410
411
 
406
407
408
409
410
411
412
413
@@ -406,6 +406,8 @@
  <Compile Include="EnterpriseWebFramework\Form Controls\Navigational Form Control\NavFormControl.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Navigational Form Control\NavFormControlSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Navigational Form Control\NavFormControlValidationResult.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Number Control\NumberControl.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Number Control\NumberControlSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Numeric Text Control\NumericTextControl.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Numeric Text Control\NumericTextControlSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\RadioButtonGroup.cs" />
 
34
35
36
 
37
38
39
 
34
35
36
37
38
39
40
@@ -34,6 +34,7 @@
  <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CLists_005CList_0020Items/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CLists_005CSelect_0020List/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cnavigational_0020form_0020control/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cnumber_0020control/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cnumeric_0020text_0020control/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Ctelephone_0020number_0020control/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CText_0020Box/@EntryIndexedValue">True</s:Boolean>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,36 @@
+using System; +using EnterpriseWebLibrary.InputValidation; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// A number edit control. + /// </summary> + public class NumberControl: FormControl<PhrasingComponent> { + public FormControlLabeler Labeler { get; } + public PhrasingComponent PageComponent { get; } + public EwfValidation Validation { get; } + + /// <summary> + /// Creates a number control. + /// </summary> + /// <param name="value"></param> + /// <param name="allowEmpty"></param> + /// <param name="setup">The setup object for the number control.</param> + /// <param name="minValue">The smallest allowed value.</param> + /// <param name="maxValue">The largest allowed value.</param> + /// <param name="valueStep">The allowed granularity of the value. Do not pass zero or a negative number. Pass null to allow any value.</param> + /// <param name="validationMethod">The validation method. Pass null if you’re only using this control for page modification.</param> + public NumberControl( + decimal? value, bool allowEmpty, NumberControlSetup setup = null, decimal? minValue = null, decimal? maxValue = null, decimal? valueStep = null, + Action<decimal?, Validator> validationMethod = null ) { + setup = setup ?? NumberControlSetup.Create(); + ( Labeler, PageComponent, Validation ) = setup.LabelerAndComponentAndValidationGetter( + value, + allowEmpty, + minValue, + maxValue, + valueStep, + validationMethod ); + } + } +} \ No newline at end of file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
 
@@ -0,0 +1,269 @@
+using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using EnterpriseWebLibrary.InputValidation; +using Humanizer; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// The configuration for a number control. + /// </summary> + public class NumberControlSetup { + /// <summary> + /// Creates a setup object for a standard number control. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</param> + /// <param name="placeholder">The hint word or phrase that will appear when the control has an empty value. Do not pass null.</param> + /// <param name="autoFillTokens">A list of auto-fill detail tokens (see + /// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-detail-tokens), or "off" to instruct the browser to disable auto-fill + /// (see https://stackoverflow.com/a/23234498/35349 for an explanation of why this could be ignored). Do not pass null.</param> + /// <param name="action">The action that will occur when the user hits Enter on the control. Pass null to use the current default action. Currently has no + /// effect for multiline controls.</param> + /// <param name="valueChangedAction">The action that will occur when the value is changed. Pass null for no action.</param> + /// <param name="pageModificationValue"></param> + /// <param name="validationPredicate"></param> + /// <param name="validationErrorNotifier"></param> + public static NumberControlSetup Create( + DisplaySetup displaySetup = null, ElementClassSet classes = null, string placeholder = "", string autoFillTokens = "", FormAction action = null, + FormAction valueChangedAction = null, PageModificationValue<decimal?> pageModificationValue = null, Func<bool, bool> validationPredicate = null, + Action validationErrorNotifier = null ) { + return new NumberControlSetup( + displaySetup, + false, + false, + classes, + placeholder, + autoFillTokens, + null, + action, + null, + valueChangedAction, + pageModificationValue ?? new PageModificationValue<decimal?>(), + validationPredicate, + validationErrorNotifier ); + } + + /// <summary> + /// Creates a setup object for a number control with auto-complete behavior. + /// </summary> + /// <param name="autoCompleteResource">The resource containing the auto-complete items. Do not pass null.</param> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</param> + /// <param name="placeholder">The hint word or phrase that will appear when the control has an empty value. Do not pass null.</param> + /// <param name="autoFillTokens">A list of auto-fill detail tokens (see + /// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-detail-tokens), or "off" to instruct the browser to disable auto-fill + /// (see https://stackoverflow.com/a/23234498/35349 for an explanation of why this could be ignored). Do not pass null.</param> + /// <param name="action">The action that will occur when the user hits Enter on the control. Pass null to use the current default action. Currently has no + /// effect for multiline controls.</param> + /// <param name="triggersActionWhenItemSelected">Pass true to also trigger the action when the user selects an auto-complete item.</param> + /// <param name="valueChangedAction">The action that will occur when the value is changed. Pass null for no action.</param> + /// <param name="pageModificationValue"></param> + /// <param name="validationPredicate"></param> + /// <param name="validationErrorNotifier"></param> + public static NumberControlSetup CreateAutoComplete( + ResourceInfo autoCompleteResource, DisplaySetup displaySetup = null, ElementClassSet classes = null, string placeholder = "", string autoFillTokens = "", + FormAction action = null, bool triggersActionWhenItemSelected = false, FormAction valueChangedAction = null, + PageModificationValue<decimal?> pageModificationValue = null, Func<bool, bool> validationPredicate = null, Action validationErrorNotifier = null ) { + return new NumberControlSetup( + displaySetup, + false, + false, + classes, + placeholder, + autoFillTokens, + autoCompleteResource, + action, + triggersActionWhenItemSelected, + valueChangedAction, + pageModificationValue ?? new PageModificationValue<decimal?>(), + validationPredicate, + validationErrorNotifier ); + } + + /// <summary> + /// Creates a setup object for a read-only number control. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</param> + /// <param name="validationPredicate"></param> + /// <param name="validationErrorNotifier"></param> + public static NumberControlSetup CreateReadOnly( + DisplaySetup displaySetup = null, ElementClassSet classes = null, Func<bool, bool> validationPredicate = null, Action validationErrorNotifier = null ) { + return new NumberControlSetup( + displaySetup, + false, + true, + classes, + "", + "", + null, + null, + null, + null, + new PageModificationValue<decimal?>(), + validationPredicate, + validationErrorNotifier ); + } + + internal readonly Func<decimal?, bool, decimal?, decimal?, decimal?, Action<decimal?, Validator>, ( FormControlLabeler, PhrasingComponent, EwfValidation )> + LabelerAndComponentAndValidationGetter; + + internal NumberControlSetup( + DisplaySetup displaySetup, bool isImprecise, bool isReadOnly, ElementClassSet classes, string placeholder, string autoFillTokens, + ResourceInfo autoCompleteResource, FormAction action, bool? triggersActionWhenItemSelected, FormAction valueChangedAction, object pageModificationValue, + Func<bool, bool> validationPredicate, Action validationErrorNotifier ) { + var labeler = new FormControlLabeler(); + action = action ?? FormState.Current.DefaultAction; + + LabelerAndComponentAndValidationGetter = ( value, allowEmpty, minValue, maxValue, valueStep, validationMethod ) => { + var id = new ElementId(); + var formValue = new FormValue<decimal?>( + () => value, + () => isReadOnly ? "" : id.Id, + v => v.ToString(), + rawValue => rawValue == null ? PostBackValueValidationResult<decimal?>.CreateInvalid() : + !rawValue.Any() && !isImprecise ? PostBackValueValidationResult<decimal?>.CreateValid( null ) : + !decimal.TryParse( + rawValue, + NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, + CultureInfo.InvariantCulture, + out var result ) ? PostBackValueValidationResult<decimal?>.CreateInvalid() : + PostBackValueValidationResult<decimal?>.CreateValid( result ) ); + + if( isImprecise ) + formValue.AddPageModificationValue( (PageModificationValue<decimal>)pageModificationValue, v => v.Value ); + else + formValue.AddPageModificationValue( (PageModificationValue<decimal?>)pageModificationValue, v => v ); + + return ( labeler, new CustomPhrasingComponent( + new DisplayableElement( + context => { + id.AddId( context.Id ); + labeler.AddControlId( context.Id ); + + if( !isReadOnly ) { + action.AddToPageIfNecessary(); + valueChangedAction?.AddToPageIfNecessary(); + } + + return new DisplayableElementData( + displaySetup, + () => { + var attributes = new List<Tuple<string, string>>(); + attributes.Add( Tuple.Create( "type", isImprecise ? "range" : "number" ) ); + if( !isReadOnly ) + attributes.Add( Tuple.Create( "name", context.Id ) ); + + var pmvValue = isImprecise + ? ( (PageModificationValue<decimal>)pageModificationValue ).Value + : ( (PageModificationValue<decimal?>)pageModificationValue ).Value; + attributes.Add( Tuple.Create( "value", getHtmlFloatingPointNumber( pmvValue ) ) ); + if( isReadOnly ) + attributes.Add( Tuple.Create( "disabled", "disabled" ) ); + if( !isReadOnly ) { + if( minValue.HasValue ) + attributes.Add( Tuple.Create( "min", getHtmlFloatingPointNumber( minValue.Value ) ) ); + if( maxValue.HasValue ) + attributes.Add( Tuple.Create( "max", getHtmlFloatingPointNumber( maxValue.Value ) ) ); + attributes.Add( Tuple.Create( "step", valueStep.HasValue ? getHtmlFloatingPointNumber( valueStep.Value ) : "any" ) ); + } + if( placeholder.Any() ) + attributes.Add( Tuple.Create( "placeholder", placeholder ) ); + if( autoFillTokens.Any() ) + attributes.Add( Tuple.Create( "autocomplete", autoFillTokens ) ); + + + var autoCompleteStatements = ""; + if( autoCompleteResource != null ) { + const int delay = 250; // Default delay is 300 ms. + const int minCharacters = 3; + + var autocompleteOptions = new List<Tuple<string, string>>(); + autocompleteOptions.Add( Tuple.Create( "delay", delay.ToString() ) ); + autocompleteOptions.Add( Tuple.Create( "minLength", minCharacters.ToString() ) ); + autocompleteOptions.Add( Tuple.Create( "source", "'" + autoCompleteResource.GetUrl() + "'" ) ); + + if( triggersActionWhenItemSelected.Value ) { + var handler = "function( event, ui ) {{ $( '#{0}' ).val( ui.item.value ); {1} return false; }}".FormatWith( + context.Id, + action.GetJsStatements() ); + autocompleteOptions.Add( Tuple.Create( "select", handler ) ); + } + + autoCompleteStatements = "$( '#{0}' ).autocomplete( {{ {1} }} );".FormatWith( + context.Id, + autocompleteOptions.Select( o => "{0}: {1}".FormatWith( o.Item1, o.Item2 ) ).GetCommaDelimitedStringFromCollection() ); + } + + var jsInitStatements = StringTools.ConcatenateWithDelimiter( + " ", + !isReadOnly + ? SubmitButton.GetImplicitSubmissionKeyPressStatements( action, valueChangedAction != null ) + .Surround( "$( '#{0}' ).keypress( function( e ) {{ ".FormatWith( context.Id ), " } );" ) + : "", + valueChangedAction != null + ? + // Use setTimeout to prevent keypress and change from *both* triggering actions at the same time when Enter is pressed after a text + // change. + "$( '#{0}' ).change( function() {{ {1} }} );".FormatWith( + context.Id, + "setTimeout( function() { " + valueChangedAction.GetJsStatements() + " }, 0 );" ) + : "", + isImprecise + ? ( (PageModificationValue<decimal>)pageModificationValue ).GetJsModificationStatements( "Number( $( this ).val() )" ) + : ( (PageModificationValue<decimal?>)pageModificationValue ).GetJsModificationStatements( "Number( $( this ).val() )" ) + .Surround( "$( '#{0}' ).change( function() {{ ".FormatWith( context.Id ), " } );" ), + autoCompleteStatements ); + + return new DisplayableElementLocalData( + "input", + new FocusabilityCondition( true ), + isFocused => { + if( isFocused ) + attributes.Add( Tuple.Create( "autofocus", "autofocus" ) ); + return new DisplayableElementFocusDependentData( attributes: attributes, includeIdAttribute: true, jsInitStatements: jsInitStatements ); + } ); + }, + classes: TextControlSetup.ElementClass.Add( classes ?? ElementClassSet.Empty ) ); + }, + formValue: formValue ).ToCollection() ), validationMethod == null + ? null + : formValue.CreateValidation( + ( postBackValue, validator ) => { + if( validationPredicate != null && !validationPredicate( postBackValue.ChangedOnPostBack ) ) + return; + + if( postBackValue.Value.HasValue ) { + if( minValue.HasValue && postBackValue.Value.Value < minValue.Value ) { + validator.NoteErrorAndAddMessage( "The value is too small." ); + validationErrorNotifier?.Invoke(); + return; + } + if( maxValue.HasValue && postBackValue.Value.Value > maxValue.Value ) { + validator.NoteErrorAndAddMessage( "The value is too large." ); + validationErrorNotifier?.Invoke(); + return; + } + if( valueStep.HasValue && ( postBackValue.Value.Value - ( minValue ?? value ?? 0 ) ) % + valueStep.Value != 0 ) { + validator.NoteErrorAndAddMessage( "The value is not an allowed step." ); + validationErrorNotifier?.Invoke(); + return; + } + } + else if( !allowEmpty ) { + validator.NoteErrorAndAddMessage( "Please enter a value." ); + validationErrorNotifier?.Invoke(); + return; + } + + validationMethod( postBackValue.Value, validator ); + } ) ); + }; + } + + private string getHtmlFloatingPointNumber( decimal? value ) => value.HasValue ? value.Value.ToString( "G", CultureInfo.InvariantCulture ) : ""; + } +} \ No newline at end of file
 
11
12
13
14
 
15
16
17
 
33
34
35
36
37
 
 
38
39
40
 
336
337
338
339
 
340
341
342
 
11
12
13
 
14
15
16
17
 
33
34
35
 
 
36
37
38
39
40
 
336
337
338
 
339
340
341
342
@@ -11,7 +11,7 @@
  /// The configuration for a text control.   /// </summary>   public class TextControlSetup { - private static readonly ElementClass elementClass = new ElementClass( "ewfTextC" ); + internal static readonly ElementClass ElementClass = new ElementClass( "ewfTextC" );     [ UsedImplicitly ]   private class CssElementCreator: ControlCssElementCreator { @@ -33,8 +33,8 @@
  };   }   - private string getSingleLineSelector( string suffix ) => "input.{0}".FormatWith( elementClass.ClassName ) + suffix; - private string getMultilineSelector( string suffix ) => "textarea.{0}".FormatWith( elementClass.ClassName ) + suffix; + private string getSingleLineSelector( string suffix ) => "input.{0}".FormatWith( ElementClass.ClassName ) + suffix; + private string getMultilineSelector( string suffix ) => "textarea.{0}".FormatWith( ElementClass.ClassName ) + suffix;   }     internal static string GetTextareaValue( string value ) { @@ -336,7 +336,7 @@
  return new DisplayableElementFocusDependentData( attributes: attributes, includeIdAttribute: true, jsInitStatements: jsInitStatements );   } );   }, - classes: elementClass.Add( classes ?? ElementClassSet.Empty ), + classes: ElementClass.Add( classes ?? ElementClassSet.Empty ),   children: inputElementType.Any() ? null : new TextNode( () => GetTextareaValue( pageModificationValue.Value ) ).ToCollection() );   },   formValue: formValue ).ToCollection() ), externalValidationMethod == null
 
25
26
27
 
28
29
30
 
25
26
27
28
29
30
31
@@ -25,6 +25,7 @@
  new ResourceGroup(   "Form Controls",   new TextControlDemo.Info( this ), + new NumberControlDemo.Info( this ),   new CheckBox.Info( this ),   new CheckBoxList.Info( this ),   new SelectListDemo.Info( this ),
Change 1 of 1 Show Entire File Web Site/​TestPages/​NumberControlDemo.aspx Stacked
 
 
 
 
 
 
 
1
2
3
4
5
@@ -0,0 +1,5 @@
+<%@ Page Language="C#" CodeBehind="NumberControlDemo.aspx.cs" Inherits="EnterpriseWebLibrary.WebSite.TestPages.NumberControlDemo" MasterPageFile="~/Ewf/EwfUi.master" %> + +<asp:Content runat="server" ContentPlaceHolderID="contentPlace"> + <asp:PlaceHolder runat="server" ID="ph" /> +</asp:Content>
Change 1 of 1 Show Entire File Web Site/​TestPages/​NumberControlDemo.aspx.cs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,83 @@
+using System; +using System.Collections.Generic; +using System.Linq; +using EnterpriseWebLibrary.EnterpriseWebFramework; +using EnterpriseWebLibrary.WebSessionState; +using Humanizer; + +namespace EnterpriseWebLibrary.WebSite.TestPages { + partial class NumberControlDemo: EwfPage { + partial class Info { + public override string ResourceName => "Number Control"; + } + + protected override void loadData() { + ph.AddControlsReturnThis( + FormState.ExecuteWithDataModificationsAndDefaultAction( + PostBack.CreateFull().ToCollection(), + () => { + var table = FormItemBlock.CreateFormItemTable( formItems: getControls().Select( ( getter, i ) => getter( ( i + 1 ).ToString() ) ) ); + table.IncludeButtonWithThisText = "Submit"; + return table; + } ), + FormItemBlock.CreateFormItemTable( + heading: "Independent Controls", + formItems: getIndependentControls().Select( ( getter, i ) => getter( "I-" + ( i + 1 ).ToString() ) ) ) ); + } + + private IReadOnlyCollection<Func<string, FormItem>> getControls() => + new[] + { + get( "Standard", null ), get( "[1,2] with .25 step", null, minValue: 1, maxValue: 2, valueStep: .25m ), + get( "Placeholder", NumberControlSetup.Create( placeholder: "Type here" ) ), + get( "Birthday year auto-fill", NumberControlSetup.Create( autoFillTokens: "bday-year" ) ), + get( "Auto-complete", NumberControlSetup.CreateAutoComplete( TestService.GetInfo() ) ), id => { + var pb = PostBack.CreateIntermediate( null, id: id ); + return FormState.ExecuteWithDataModificationsAndDefaultAction( + FormState.Current.DataModifications.Append( pb ), + () => get( "Separate value-changed action", NumberControlSetup.Create( valueChangedAction: new PostBackFormAction( pb ) ) )( id ) ); + }, + get( "Read-only", NumberControlSetup.CreateReadOnly() ) + }; + + private IReadOnlyCollection<Func<string, FormItem>> getIndependentControls() => + new Func<string, FormItem>[] + { + id => { + var pb = PostBack.CreateFull( id: id ); + return FormState.ExecuteWithDataModificationsAndDefaultAction( pb.ToCollection(), () => get( "Standard", null )( id ) ); + }, + id => { + var pb = PostBack.CreateFull( id: id ); + return FormState.ExecuteWithDataModificationsAndDefaultAction( + pb.ToCollection(), + () => get( + "Auto-complete, triggers action when item selected", + NumberControlSetup.CreateAutoComplete( TestService.GetInfo(), triggersActionWhenItemSelected: true ) )( id ) ); + }, + id => { + var pb = PostBack.CreateFull( id: id ); + return FormState.ExecuteWithDataModificationsAndDefaultAction( + pb.ToCollection(), + () => get( + "Auto-complete, triggers action when item selected or value changed", + NumberControlSetup.CreateAutoComplete( + TestService.GetInfo(), + triggersActionWhenItemSelected: true, + valueChangedAction: new PostBackFormAction( pb ) ) )( id ) ); + } + }; + + private Func<string, FormItem> + get( string label, NumberControlSetup setup, decimal? minValue = null, decimal? maxValue = null, decimal? valueStep = null ) => + id => new NumberControl( + null, + true, + setup: setup, + minValue: minValue, + maxValue: maxValue, + valueStep: valueStep, + validationMethod: ( postBackValue, validator ) => AddStatusMessage( StatusMessageType.Info, "{0}: {1}".FormatWith( id, postBackValue ) ) ).ToFormItem( + label: "{0}. {1}".FormatWith( id, label ).ToComponents() ); + } +} \ No newline at end of file
Change 1 of 1 Show Entire File Web Site/​TestPages/​NumberControlDemo.aspx.designer.cs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@@ -0,0 +1,24 @@
+//------------------------------------------------------------------------------ +// <auto-generated> +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace EnterpriseWebLibrary.WebSite.TestPages { + + + public partial class NumberControlDemo { + + /// <summary> + /// ph control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.PlaceHolder ph; + } +}
 
320
321
322
 
 
 
 
 
 
 
323
324
325
 
533
534
535
 
536
537
538
 
320
321
322
323
324
325
326
327
328
329
330
331
332
 
540
541
542
543
544
545
546
@@ -320,6 +320,13 @@
  <Compile Include="TestPages\ModalBoxes.aspx.designer.cs">   <DependentUpon>ModalBoxes.aspx</DependentUpon>   </Compile> + <Compile Include="TestPages\NumberControlDemo.aspx.cs"> + <DependentUpon>NumberControlDemo.aspx</DependentUpon> + <SubType>ASPXCodeBehind</SubType> + </Compile> + <Compile Include="TestPages\NumberControlDemo.aspx.designer.cs"> + <DependentUpon>NumberControlDemo.aspx</DependentUpon> + </Compile>   <Compile Include="TestPages\OmniDemo.aspx.cs">   <DependentUpon>OmniDemo.aspx</DependentUpon>   <SubType>ASPXCodeBehind</SubType> @@ -533,6 +540,7 @@
  <Content Include="TestPages\IntermediatePostBacks.aspx" />   <Content Include="TestPages\MailMerging.aspx" />   <Content Include="TestPages\ModalBoxes.aspx" /> + <Content Include="TestPages\NumberControlDemo.aspx" />   <Content Include="TestPages\OmniDemo.aspx" />   <Content Include="TestPages\OptionalParameters.aspx" />   <Content Include="Ewf\ErrorPages\AccessDenied.aspx" />