get( string label, NumberControlSetup setup, PageModificationValue <decimal?> pageModificationValue = null, 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() .Concat( pageModificationValue != null ? new LineBreak().ToCollection <PhrasingComponent>() .Append( new SideComments( "Value: ".ToComponents() .Concat( pageModificationValue.ToGenericPhrasingContainer( v => v?.Normalize().ToString() ?? "", valueExpression => "{0}.toString()".FormatWith(valueExpression))) .Materialize())) : Enumerable.Empty <PhrasingComponent>()) .Materialize());
private Func <string, FormItem> getRadioGroup( string label, RadioButtonSetup setup, bool noSelection = false, bool singleButton = false, FormAction selectionChangedAction = null, PageModificationValue <bool> pageModificationValue = null) => id => { var group = new RadioButtonGroup(noSelection, disableSingleButtonDetection: singleButton, selectionChangedAction: selectionChangedAction); return(new StackList( group .CreateRadioButton( !noSelection, "First".ToComponents(), setup: setup, validationMethod: (postBackValue, validator) => AddStatusMessage( StatusMessageType.Info, "{0}-1: {1}".FormatWith(id, postBackValue.Value.ToString()))) .ToFormItem() .ToListItem() .ToCollection() .Concat( singleButton ? Enumerable.Empty <ComponentListItem>() : group.CreateFlowRadioButton( false, "Second".ToComponents(), setup: FlowRadioButtonSetup.Create( nestedContentGetter: () => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit.".ToComponents()), validationMethod: (postBackValue, validator) => AddStatusMessage( StatusMessageType.Info, "{0}-2: {1}".FormatWith(id, postBackValue.Value.ToString()))) .ToFormItem() .ToListItem() .ToCollection() .Append( group.CreateRadioButton( false, "Third".ToComponents(), setup: RadioButtonSetup.Create(), validationMethod: (postBackValue, validator) => AddStatusMessage( StatusMessageType.Info, "{0}-3: {1}".FormatWith(id, postBackValue.Value.ToString()))) .ToFormItem() .ToListItem()))).ToFormItem( label: "{0}. {1}".FormatWith(id, label) .ToComponents() .Concat( pageModificationValue != null ? new LineBreak().ToCollection <PhrasingComponent>() .Append( new SideComments( "First button value: ".ToComponents() .Concat( pageModificationValue.ToGenericPhrasingContainer( v => v.ToString(), valueExpression => "{0} ? 'True' : 'False'".FormatWith(valueExpression))) .Materialize())) : Enumerable.Empty <PhrasingComponent>()) .Materialize())); };
private RadioButtonSetup( DisplaySetup displaySetup, bool isReadOnly, ElementClassSet classes, SpecifiedValue <FormAction> action, PageModificationValue <bool> pageModificationValue) { DisplaySetup = displaySetup; IsReadOnly = isReadOnly; Classes = classes; Action = action != null ? action.Value : FormState.Current.FormControlDefaultAction; PageModificationValue = pageModificationValue ?? new PageModificationValue <bool>(); }
private IReadOnlyCollection <Func <string, FormItem> > getControls() => new[] { getCheckbox("Standard", null), id => { var pb = PostBack.CreateIntermediate(null, id: id); return(FormState.ExecuteWithDataModificationsAndDefaultAction( FormState.Current.DataModifications.Append(pb), () => getCheckbox("Separate value-changed action", CheckboxSetup.Create(valueChangedAction: new PostBackFormAction(pb)))(id))); }, new Func <Func <string, FormItem> >( () => { var pmv = new PageModificationValue <bool>(); return(getCheckbox("Page modification", CheckboxSetup.Create(pageModificationValue: pmv), pageModificationValue: pmv)); })(), getCheckbox("Read-only", CheckboxSetup.CreateReadOnly()), getFlowCheckbox("Flow", null), getFlowCheckbox("Flow with highlighting", FlowCheckboxSetup.Create(highlightedWhenChecked: true)), getFlowCheckbox( "Flow with nested content", FlowCheckboxSetup.Create( nestedContentGetter: () => new Paragraph( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id vestibulum neque. Suspendisse vel sem ac nunc condimentum tempus eget quis nunc. Morbi mattis elementum cursus. Integer eros mi, porttitor vitae orci eget, facilisis pretium diam. Aenean et nisi leo. Aenean nibh ligula, suscipit sit amet nulla ac, faucibus suscipit ipsum. Nunc quis faucibus ex." .ToComponents()).ToCollection())), getFlowCheckbox( "Flow with nested content always displayed", FlowCheckboxSetup.Create( nestedContentGetter: () => new Paragraph( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel diam quis felis accumsan tempus. Nunc hendrerit mi in hendrerit finibus. Nullam aliquet pharetra mauris ac vehicula. Quisque vehicula imperdiet pulvinar. Morbi ullamcorper est non arcu suscipit, quis interdum ex egestas. Sed vel risus vitae nisl scelerisque pretium. Aliquam vel pretium orci, eu scelerisque felis. Morbi ac auctor lacus, sit amet congue nunc." .ToComponents()).ToCollection(), nestedContentAlwaysDisplayed: true)), getRadioGroup("Radio group", null), getRadioGroup("Radio group with no selection", null, noSelection: true), getRadioGroup("Radio group with single button", null, singleButton: true), id => { var pb = PostBack.CreateIntermediate(null, id: id); return(FormState.ExecuteWithDataModificationsAndDefaultAction( FormState.Current.DataModifications.Append(pb), () => getRadioGroup("Radio group with separate selection-changed action", null, selectionChangedAction: new PostBackFormAction(pb))(id))); }, new Func <Func <string, FormItem> >( () => { var pmv = new PageModificationValue <bool>(); return(getRadioGroup("Radio group with page modification", RadioButtonSetup.Create(pageModificationValue: pmv), pageModificationValue: pmv)); })(), getRadioGroup("Radio group with read-only button", RadioButtonSetup.CreateReadOnly()) };
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))); }, new Func <Func <string, FormItem> >( () => { var pmv = new PageModificationValue <decimal?>(); return(get("Page modification", NumberControlSetup.Create(pageModificationValue: pmv), pageModificationValue: pmv)); })(), 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))); }, new Func <Func <string, FormItem> >( () => { var pmv = new PageModificationValue <decimal>(); return(getImprecise( "Imprecise with page modification", ImpreciseNumberControlSetup.Create(pageModificationValue: pmv), pageModificationValue: pmv)); })(), getImprecise("Imprecise read-only", ImpreciseNumberControlSetup.CreateReadOnly()) };
private Func <string, FormItem> getCheckbox(string label, CheckboxSetup setup, PageModificationValue <bool> pageModificationValue = null) => id => new Checkbox( false, "Lorem ipsum dolor sit amet".ToComponents(), setup: setup, validationMethod: (postBackValue, validator) => AddStatusMessage( StatusMessageType.Info, "{0}: {1}".FormatWith(id, postBackValue.Value.ToString()))).ToFormItem( label: "{0}. {1}".FormatWith(id, label) .ToComponents() .Concat( pageModificationValue != null ? new LineBreak().ToCollection <PhrasingComponent>() .Append( new SideComments( "Value: ".ToComponents() .Concat( pageModificationValue.ToGenericPhrasingContainer( v => v.ToString(), valueExpression => "{0} ? 'True' : 'False'".FormatWith(valueExpression))) .Materialize())) : Enumerable.Empty <PhrasingComponent>()) .Materialize());
/// <summary> /// Creates a setup object for a standard checkbox. /// </summary> /// <param name="displaySetup"></param> /// <param name="classes">The classes on the control.</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.</param> /// <param name="valueChangedAction">The action that will occur when the value is changed. Pass null for no action.</param> /// <param name="pageModificationValue"></param> public static CheckboxSetup Create( DisplaySetup displaySetup = null, ElementClassSet classes = null, SpecifiedValue <FormAction> action = null, FormAction valueChangedAction = null, PageModificationValue <bool> pageModificationValue = null) { return(new CheckboxSetup(displaySetup, false, classes, action, valueChangedAction, pageModificationValue)); }
/// <summary> /// Creates a setup object for a standard radio button. /// </summary> /// <param name="displaySetup"></param> /// <param name="classes">The classes on the control.</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.</param> /// <param name="pageModificationValue"></param> public static RadioButtonSetup Create( DisplaySetup displaySetup = null, ElementClassSet classes = null, SpecifiedValue <FormAction> action = null, PageModificationValue <bool> pageModificationValue = null) { return(new RadioButtonSetup(displaySetup, false, classes, action, pageModificationValue)); }