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

Created ImpreciseNumberControl.

Changeset d952ba5fa687

Parent 7df8b0f50c6c

by Profile picture of William GrossWilliam Gross

Changes to 6 files · Browse files at d952ba5fa687 Showing diff from parent 7df8b0f50c6c Diff from another changeset...

Change 1 of 1 Show Entire File Core/​Core.csproj Stacked
 
397
398
399
 
 
400
401
402
 
397
398
399
400
401
402
403
404
@@ -397,6 +397,8 @@
  <Compile Include="EnterpriseWebFramework\Form Controls\HiddenFieldId.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\HTML Editor\WysiwygHtmlEditor.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\HTML Editor\WysiwygHtmlEditorSetup.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Imprecise Number Control\ImpreciseNumberControl.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\Imprecise Number Control\ImpreciseNumberControlSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Lists\ChangeBasedCheckBoxList.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Lists\List Items\ChangeBasedListItem.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Lists\List Items\ChangeBasedListItemWithSelectionState.cs" />
 
30
31
32
 
33
34
35
 
30
31
32
33
34
35
36
@@ -30,6 +30,7 @@
  <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cdate_0020and_0020time/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cemail_0020address_0020control/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Chtml_0020editor/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cform_0020controls_005Cimprecise_0020number_0020control/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CForm_0020Controls_005CLists/@EntryIndexedValue">True</s:Boolean>   <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>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,35 @@
+using System; +using EnterpriseWebLibrary.InputValidation; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// An imprecise-number edit control. + /// </summary> + public class ImpreciseNumberControl: FormControl<PhrasingComponent> { + public FormControlLabeler Labeler { get; } + public PhrasingComponent PageComponent { get; } + public EwfValidation Validation { get; } + + /// <summary> + /// Creates an imprecise-number control. + /// </summary> + /// <param name="value"></param> + /// <param name="minValue">The smallest allowed value.</param> + /// <param name="maxValue">The largest allowed value.</param> + /// <param name="setup">The setup object for the imprecise-number control.</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 ImpreciseNumberControl( + decimal value, decimal minValue, decimal maxValue, ImpreciseNumberControlSetup setup = null, decimal? valueStep = null, + Action<decimal, Validator> validationMethod = null ) { + setup = setup ?? ImpreciseNumberControlSetup.Create(); + ( Labeler, PageComponent, Validation ) = setup.NumberControlSetup.LabelerAndComponentAndValidationGetter( + value, + false, + minValue, + maxValue, + valueStep, + ( postBackValue, validator ) => validationMethod( postBackValue.Value, validator ) ); + } + } +} \ 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
 
@@ -0,0 +1,75 @@
+using System; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// The configuration for an imprecise-number control. + /// </summary> + public class ImpreciseNumberControlSetup { + /// <summary> + /// Creates a setup object for a standard imprecise-number control. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="classes">The classes on the control.</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 ImpreciseNumberControlSetup Create( + DisplaySetup displaySetup = null, ElementClassSet classes = null, string autoFillTokens = "", FormAction action = null, + FormAction valueChangedAction = null, PageModificationValue<decimal> pageModificationValue = null, Func<bool, bool> validationPredicate = null, + Action validationErrorNotifier = null ) { + return new ImpreciseNumberControlSetup( + new NumberControlSetup( + displaySetup, + true, + false, + classes, + "", + autoFillTokens, + null, + action, + null, + valueChangedAction, + pageModificationValue ?? new PageModificationValue<decimal>(), + validationPredicate, + validationErrorNotifier ) ); + } + + /// <summary> + /// Creates a setup object for a read-only imprecise-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 ImpreciseNumberControlSetup CreateReadOnly( + DisplaySetup displaySetup = null, ElementClassSet classes = null, Func<bool, bool> validationPredicate = null, Action validationErrorNotifier = null ) { + return new ImpreciseNumberControlSetup( + new NumberControlSetup( + displaySetup, + true, + true, + classes, + "", + "", + null, + null, + null, + null, + new PageModificationValue<decimal>(), + validationPredicate, + validationErrorNotifier ) ); + } + + internal NumberControlSetup NumberControlSetup { get; } + + private ImpreciseNumberControlSetup( NumberControlSetup numberControlSetup ) { + NumberControlSetup = numberControlSetup; + } + } +} \ No newline at end of file
 
33
34
35
36
 
37
38
39
 
70
71
72
73
 
74
75
76
 
95
96
97
98
 
99
100
101
 
226
227
228
229
 
230
231
232
 
33
34
35
 
36
37
38
39
 
70
71
72
 
73
74
75
76
 
95
96
97
 
98
99
100
101
 
226
227
228
 
229
230
231
232
@@ -33,7 +33,7 @@
  displaySetup,   false,   false, - classes, + TextControlSetup.ElementClass.Add( classes ?? ElementClassSet.Empty ),   placeholder,   autoFillTokens,   null, @@ -70,7 +70,7 @@
  displaySetup,   false,   false, - classes, + TextControlSetup.ElementClass.Add( classes ?? ElementClassSet.Empty ),   placeholder,   autoFillTokens,   autoCompleteResource, @@ -95,7 +95,7 @@
  displaySetup,   false,   true, - classes, + TextControlSetup.ElementClass.Add( classes ?? ElementClassSet.Empty ),   "",   "",   null, @@ -226,7 +226,7 @@
  return new DisplayableElementFocusDependentData( attributes: attributes, includeIdAttribute: true, jsInitStatements: jsInitStatements );   } );   }, - classes: TextControlSetup.ElementClass.Add( classes ?? ElementClassSet.Empty ) ); + classes: classes );   },   formValue: formValue ).ToCollection() ), validationMethod == null   ? null
 
37
38
39
40
 
 
 
 
 
 
 
 
 
 
41
42
43
 
79
80
81
 
 
 
 
 
 
 
 
 
 
 
82
83
 
 
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
52
 
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 
@@ -37,7 +37,16 @@
  FormState.Current.DataModifications.Append( pb ),   () => get( "Separate value-changed action", NumberControlSetup.Create( valueChangedAction: new PostBackFormAction( pb ) ) )( id ) );   }, - get( "Read-only", NumberControlSetup.CreateReadOnly() ) + get( "Read-only", NumberControlSetup.CreateReadOnly() ), getImprecise( "Imprecise", null ), + getImprecise( "Imprecise [1,2] with .25 step", null, minValue: 1, maxValue: 2, valueStep: .25m ), id => { + var pb = PostBack.CreateIntermediate( null, id: id ); + return FormState.ExecuteWithDataModificationsAndDefaultAction( + FormState.Current.DataModifications.Append( pb ), + () => getImprecise( + "Imprecise with separate value-changed action", + ImpreciseNumberControlSetup.Create( valueChangedAction: new PostBackFormAction( pb ) ) )( id ) ); + }, + getImprecise( "Imprecise read-only", ImpreciseNumberControlSetup.CreateReadOnly() )   };     private IReadOnlyCollection<Func<string, FormItem>> getIndependentControls() => @@ -79,5 +88,16 @@
  valueStep: valueStep,   validationMethod: ( postBackValue, validator ) => AddStatusMessage( StatusMessageType.Info, "{0}: {1}".FormatWith( id, postBackValue ) ) ).ToFormItem(   label: "{0}. {1}".FormatWith( id, label ).ToComponents() ); + + private Func<string, FormItem> getImprecise( + string label, ImpreciseNumberControlSetup setup, decimal? minValue = null, decimal? maxValue = null, decimal? valueStep = null ) => + id => new ImpreciseNumberControl( + .25m, + minValue ?? 0, + maxValue ?? 1, + setup: setup, + 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