/// <summary> /// Creates a checkbox. /// </summary> /// <param name="value"></param> /// <param name="label">The checkbox label. Do not pass null. Pass an empty collection for no label.</param> /// <param name="setup">The setup object for the checkbox.</param> /// <param name="validationMethod">The validation method. Pass null if you’re only using this control for page modification.</param> public Checkbox( bool value, IReadOnlyCollection <PhrasingComponent> label, CheckboxSetup setup = null, Action <PostBackValue <bool>, Validator> validationMethod = null) { setup = setup ?? CheckboxSetup.Create(); var id = new ElementId(); var formValue = new FormValue <bool>( () => value, () => setup.IsReadOnly ? "" : id.Id, v => v.ToString(), rawValue => rawValue == null ? PostBackValueValidationResult <bool> .CreateValid(false) : rawValue == "on" ? PostBackValueValidationResult <bool> .CreateValid(true) : PostBackValueValidationResult <bool> .CreateInvalid()); PageComponent = getComponent( formValue, id, null, setup.DisplaySetup, setup.IsReadOnly, setup.Classes, setup.PageModificationValue, label, setup.Action, setup.ValueChangedAction, () => (setup.ValueChangedAction?.GetJsStatements() ?? "").ConcatenateWithSpace( setup.PageModificationValue.GetJsModificationStatements("this.checked"))); formValue.AddPageModificationValue(setup.PageModificationValue, v => v); if (validationMethod != null) { Validation = formValue.CreateValidation(validationMethod); } }
private FlowCheckboxSetup( DisplaySetup displaySetup, ElementClassSet classes, CheckboxSetup checkboxSetup, bool highlightedWhenChecked, Func <IReadOnlyCollection <FlowComponent> > nestedContentGetter, bool nestedContentAlwaysDisplayed) { DisplaySetup = displaySetup; Classes = classes; CheckboxSetup = checkboxSetup; HighlightedWhenChecked = highlightedWhenChecked; NestedContentGetter = nestedContentGetter; NestedContentAlwaysDisplayed = nestedContentAlwaysDisplayed; }
/// <summary> /// Creates a setup object for a read-only checkbox. /// </summary> /// <param name="displaySetup"></param> /// <param name="classes">The classes on the container.</param> /// <param name="highlightedWhenChecked"></param> /// <param name="nestedContentGetter">A function that gets the content that will appear beneath the checkbox.</param> /// <param name="nestedContentAlwaysDisplayed">Pass true to force the nested content to always be displayed instead of only when the box is checked.</param> public static FlowCheckboxSetup CreateReadOnly( DisplaySetup displaySetup = null, ElementClassSet classes = null, bool highlightedWhenChecked = false, Func <IReadOnlyCollection <FlowComponent> > nestedContentGetter = null, bool nestedContentAlwaysDisplayed = false) { return(new FlowCheckboxSetup( displaySetup, classes, CheckboxSetup.CreateReadOnly(), highlightedWhenChecked, nestedContentGetter, nestedContentAlwaysDisplayed)); }
/// <summary> /// Creates a setup object for a standard checkbox. /// </summary> /// <param name="displaySetup"></param> /// <param name="classes">The classes on the container.</param> /// <param name="highlightedWhenChecked"></param> /// <param name="action">The action that will occur when the user hits Enter on the checkbox. Pass null to use the current default action.</param> /// <param name="valueChangedAction">The action that will occur when the checkbox value is changed. Pass null for no action.</param> /// <param name="pageModificationValue"></param> /// <param name="nestedContentGetter">A function that gets the content that will appear beneath the checkbox.</param> /// <param name="nestedContentAlwaysDisplayed">Pass true to force the nested content to always be displayed instead of only when the box is checked.</param> public static FlowCheckboxSetup Create( DisplaySetup displaySetup = null, ElementClassSet classes = null, bool highlightedWhenChecked = false, SpecifiedValue <FormAction> action = null, FormAction valueChangedAction = null, PageModificationValue <bool> pageModificationValue = null, Func <IReadOnlyCollection <FlowComponent> > nestedContentGetter = null, bool nestedContentAlwaysDisplayed = false) { return(new FlowCheckboxSetup( displaySetup, classes, CheckboxSetup.Create(action: action, valueChangedAction: valueChangedAction, pageModificationValue: pageModificationValue), highlightedWhenChecked, nestedContentGetter, nestedContentAlwaysDisplayed)); }