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

Wrapped checkbox control in label to improve clickable area.

Changeset 7826d4ed4520

Parent b3141cffb054

by Profile picture of William GrossWilliam Gross

Changes to one file · Browse files at 7826d4ed4520 Showing diff from parent b3141cffb054 Diff from another changeset...

 
15
16
17
18
 
19
20
 
21
22
23
 
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
 
15
16
17
 
18
19
 
20
21
22
23
 
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
@@ -15,9 +15,9 @@
  [ UsedImplicitly ]   private class CssElementCreator: ControlCssElementCreator {   IReadOnlyCollection<CssElement> ControlCssElementCreator.CreateCssElements() => - new CssElement( "Checkbox", "span.{0}".FormatWith( elementClass.ClassName ) ).ToCollection() + new CssElement( "Checkbox", "label.{0}".FormatWith( elementClass.ClassName ) ).ToCollection()   .Append( new CssElement( "CheckboxControl", "input.{0}".FormatWith( elementClass.ClassName ) ) ) - .Append( new CssElement( "CheckboxLabel", "label.{0}".FormatWith( elementClass.ClassName ) ) ) + .Append( new CssElement( "CheckboxLabel", "span.{0}".FormatWith( elementClass.ClassName ) ) )   .Materialize();   }   @@ -91,59 +91,62 @@
  FormValue formValue, ElementId id, string radioButtonListItemId, DisplaySetup displaySetup, bool isReadOnly, ElementClassSet classes,   PageModificationValue<bool> pageModificationValue, IReadOnlyCollection<PhrasingComponent> label, FormAction action, FormAction valueChangedAction,   Func<string> jsClickStatementGetter ) { - var labeler = new FormControlLabeler(); - return new GenericPhrasingContainer( - new CustomPhrasingComponent( - new DisplayableElement( - context => { - id.AddId( context.Id ); - labeler.AddControlId( context.Id ); + return new CustomPhrasingComponent( + new DisplayableElement( + labelContext => new DisplayableElementData( + displaySetup, + () => new DisplayableElementLocalData( "label" ), + classes: elementClass.Add( classes ?? ElementClassSet.Empty ), + children: new DisplayableElement( + context => { + id.AddId( context.Id );   - if( !isReadOnly ) { - action.AddToPageIfNecessary(); - valueChangedAction?.AddToPageIfNecessary(); - } + if( !isReadOnly ) { + action.AddToPageIfNecessary(); + valueChangedAction?.AddToPageIfNecessary(); + }   - return new DisplayableElementData( - null, - () => { - var attributes = new List<Tuple<string, string>>(); - var radioButtonFormValue = formValue as FormValue<ElementId>; - attributes.Add( Tuple.Create( "type", radioButtonFormValue != null ? "radio" : "checkbox" ) ); - if( radioButtonFormValue != null || !isReadOnly ) - attributes.Add( - Tuple.Create( "name", radioButtonFormValue != null ? ( (FormValue)radioButtonFormValue ).GetPostBackValueKey() : context.Id ) ); - if( radioButtonFormValue != null ) - attributes.Add( Tuple.Create( "value", radioButtonListItemId ?? context.Id ) ); - if( pageModificationValue.Value ) - attributes.Add( Tuple.Create( "checked", "checked" ) ); - if( isReadOnly ) - attributes.Add( Tuple.Create( "disabled", "disabled" ) ); + return new DisplayableElementData( + null, + () => { + var attributes = new List<Tuple<string, string>>(); + var radioButtonFormValue = formValue as FormValue<ElementId>; + attributes.Add( Tuple.Create( "type", radioButtonFormValue != null ? "radio" : "checkbox" ) ); + if( radioButtonFormValue != null || !isReadOnly ) + attributes.Add( + Tuple.Create( "name", radioButtonFormValue != null ? ( (FormValue)radioButtonFormValue ).GetPostBackValueKey() : context.Id ) ); + if( radioButtonFormValue != null ) + attributes.Add( Tuple.Create( "value", radioButtonListItemId ?? context.Id ) ); + if( pageModificationValue.Value ) + attributes.Add( Tuple.Create( "checked", "checked" ) ); + if( isReadOnly ) + attributes.Add( Tuple.Create( "disabled", "disabled" ) );   - var jsInitStatements = StringTools.ConcatenateWithDelimiter( - " ", - !isReadOnly - ? SubmitButton.GetImplicitSubmissionKeyPressStatements( action, false ) - .Surround( "$( '#{0}' ).keypress( function( e ) {{ ".FormatWith( context.Id ), " } );" ) - : "", - jsClickStatementGetter().Surround( "$( '#{0}' ).click( function() {{ ".FormatWith( context.Id ), " } );" ) ); + var jsInitStatements = StringTools.ConcatenateWithDelimiter( + " ", + !isReadOnly + ? SubmitButton.GetImplicitSubmissionKeyPressStatements( action, false ) + .Surround( "$( '#{0}' ).keypress( function( e ) {{ ".FormatWith( context.Id ), " } );" ) + : "", + jsClickStatementGetter().Surround( "$( '#{0}' ).click( function() {{ ".FormatWith( context.Id ), " } );" ) );   - 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: elementClass ); - }, - formValue: formValue ).ToCollection() ).ToCollection() - .Concat( label.Any() ? labeler.CreateLabel( label, classes: elementClass ) : Enumerable.Empty<PhrasingComponent>() ) - .Materialize(), - displaySetup: displaySetup, - classes: elementClass.Add( classes ?? ElementClassSet.Empty ) ); + 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: elementClass ); + }, + formValue: formValue ).ToCollection() + .Concat( label.Any() ? new GenericPhrasingContainer( label, classes: elementClass ).ToCollection() : Enumerable.Empty<FlowComponent>() ) + .Materialize() ) ).ToCollection() );   }     FormControlLabeler FormControl<PhrasingComponent>.Labeler => null;